If i have Private Function Test (ByVal mux as muxanalogvalues) as
image
how do I declare the test () function inside another sub.
if i go test (.....I need to pass the value of the mux but how do i
know what to pass)- Hide quoted text -
- Show quoted text -
As Armin suggested - a good book on Scope and OOP would be helpful.
Variables/Objects have a certain lifetime. They exists as long as the
context in which they were created in exists.
Meaning - If I have a sub, and declare some value X, that value is
only in scope as long as the sub is executing. Once the sub finishes
execution, this variable X goes out of scope.
Hence if I have:
Private sub Test()
Dim X as Integer = 10
Messagebox.Show(X)
End Sub
Every time we enter this sub, the variable X is created and has it's
value set. Since it was created within the context of the sub Test, it
only exists as long as sub Test is executing. Each time we enter the
sub Test, the variable X has no memory of it's value from previous
calls. When Test is done - variable X goes poof.
In your case - you might want to declare a value at the class level,
which will retain it's value as long as the instance of the class is
in memory. If you are writing code in a form, if you have:
Public Class Form1
private mMyValue as Integer = 1
Private Sub Test1()
Messagebox.show(mMyValue)
End Sub
End Class
When Form1 becomes instantiated, it initializes the variable mMyValue
and sets the value = 1. Hence this variable is declared at the class
level (the form in this case). As long as the form remains loaded,
mMyValue retains it's value - until the form is closed and disposed.
Since this value is declared at the class level, it is accessible
anywhere from within the class.
You asked how do you declare the test() function inside another sub.
You only declare a function once, but can call it from any other sub
in the class. Now, if your "mux" value is declared at the class level,
you really don't need to pass it to a function. As an example, I'll
assume these functions are on a form such as:
Public Class Form1
private mux as new muxanalogvalues
Private function Test() as image
'do whatever code here
'we have access to the object ref
'mux since it's declared at the class level
End Function
'now, if we want to run the code in Test() from another sub, we
simply call test()
Private sub Test2()
Test()
End Sub
End Class