Simple question!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I transfer the value of one variable in one sub to another variable in
another sub???

Thanks
 
Private Sub Page_Load(yada yada yado...)
MyNewSub(35)
End Sub

Private Sub MyNewSub(byval intUserID as integer)
Response.Write("intUserID=" & intUserID & "<br>")
End Sub
 
some context would be helpful..is one sub calling another? are they being
called by the same parent function? are they totally apart?

Karl
 
Say I have three subs! The first two subs have values I want to use in the
third sub... How do I transfer the values stored in the variables in the
first two subs into the third sub????

Thanks

EG:

Sub N01 (bla bla)
Variable 1
End Sub

Sub N02(bla Bla)
Variable2
End Sub

Sub N03(bla bla)
Variable1
Variable2
End Sub
 
Well, you have a couple options.

(a) assuming they are all in the same class, you can create private fields:

public class SomeClass
private variable1 as string
private variable2 as string

sub N01(x as x)
variable1 = "1"
'has access to variable1 and variable2
end sub

sub N02(x as x)
variable2 = "2"
'has access to variable1 and variable2
end sub

sub N03(x as x)
'has access to variable1 and variable2
end sub
end class

as long as you don't dim variable1/2 as string in the subs, they'll all use
the private fields. Alternatively, you'd pass the values around as return
values and parameters

function NO1() as string
dim variable as string ="1"
return variable
end function

function NO2() as string
dim variable as string ="2"
return variable
end function

sub NO3(variable1 as string, variable2 as string)
'local access to variable1 and variable2
end sub


Sub SomeOtherSub()
dim variable1 as string = NO1()
dim variable2 as string = NO2()
NO3(variable1, variable2)
end sub

if you need to be passing around more than one value, from NO1, you need
to return a class/struct which contains those multiple values (since you can
only return a single object).

There are other options, such as global storage mechanisms (Context and
Application in ASP.Net), but there's no indication from what you've provided
to say that such a method is required. The first method should be
sufficient. If it isn't, you'll need to provide even more context with
classes and such.

Karl
 
Here we go:

Private sub SendValue()
Dim strValueToBeSent as string = "SendMe"
CallOtherSub(strValueToBeSent)
End Sub

Private Sub CallOtherSub(strValuerecieved as string)
Dim strGiveMeTheValue as string = ""

strGiveMeTheValue = strValuerecieved
End Sub

Value passed
 
Back
Top