changing a variable value outside of a sub

  • Thread starter Thread starter Scot
  • Start date Start date
S

Scot

I have a class library with two subs in a class, summarized below:

Class

Public num As Integer = 0

Sub 1
num = 1
End Sub

Sub 2
console.writeline(num.ToString)
End Sub

End Class


When I get to Sub 2, num is 0. How would I create an integer that I can
manipulate the value of through the sub? I can't use a function instead of
the sub in this situation.

Thanks,

Scott
 
Sub2(ByRef x as Integer)

End Sub

However, if num is declared at the module level which it looks like it is,
it should be visible in Sub2
 
num is declared inside the class, which is inside a namespace. this is for
an exchange event sink, so the two subs that I am using are already defined
elsewhere. i tried adding the ByRef into sub2, but it wouldn't allow that
without errors.
 
* "Scot said:
I have a class library with two subs in a class, summarized below:

Class

Public num As Integer = 0

Sub 1
num = 1
End Sub

Sub 2
console.writeline(num.ToString)
End Sub

End Class


When I get to Sub 2, num is 0.

It's 0 if sub '1' was not already executed.
How would I create an integer that I can
manipulate the value of through the sub?

You can manipulate it by assigning it another value, like in sub '1'.
I can't use a function instead of
the sub in this situation.

Maybe I didn't get the point of your question?
 
Scot said:
I have a class library with two subs in a class, summarized below:

Class

Public num As Integer = 0


"= 0" not necessary because it's the default value.
Sub 1
num = 1
End Sub

Sub 2
console.writeline(num.ToString)
End Sub

End Class


When I get to Sub 2, num is 0. How would I create an integer that I
can manipulate the value of through the sub? I can't use a function
instead of the sub in this situation.

The code should work. You must call the subs on the same instance of the
class. Of course, sub 1 must be called first.
How did you test it?


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
If both subs are in the same class, none of that should matter. What
specific error are you getting?
 
What happens is a piece of email comes in. It gets processed through the
first sub, which has numerous conditional statements and tests. In certain
situations, I will set num = 1 in sub 1. It goes into sub2, because the
second event sink says use sub2. But when I test num with and If
condition, it is always 0, no matter what.
 
Scot said:
What happens is a piece of email comes in. It gets processed through
the first sub, which has numerous conditional statements and tests.
In certain situations, I will set num = 1 in sub 1. It goes into
sub2, because the second event sink says use sub2. But when I test
num with and If condition, it is always 0, no matter what.

You could debug the code step by step.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top