Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

quick ? about passing variables

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
If i declare a variable in one sub, but i want to pass it to another sub that I call, do i still have to declare the type of the variable like this:

sub a()
dim b as string
call c(b)
end sub

sub c(b as string) 'Is this declaration still needed??
end sub

if i leave it as subc(b), would that be made of type variant or preserve the string type, thanks!!
 
...Is this declaration still needed??

Strtictly speaking, no. But it would be a Variant which would be able to be treated as a string. Put a break point in subc and open the Locals window. It will show you the variable types.

...if i leave it as subc(b), would that be made of type variant...

Yes, but it would still be treated as a string for all practical purposes. The default for argument type is "ByRef" which means that subc is only getting a pointer to the variable b.

If you want to experiment a little more, try playing around with this to see how VBA will handle the different types (b is a variant inside of subc and a string inside of suba (put break points inside of each sub and open the Locals Window:
Code:
Sub a()
Dim b As String
b = "5"
Call c(b)
End Sub

Sub c(ByVal b As Integer)
  MsgBox b + 6
End Sub




 
ok good point...i was just asking becuase of some reference material where they say try to avoid type variant because it takes up the most memoty, so I just wanted to be on the safe side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top