Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: Class Variable passed byval is adjusted in Sub [28]

0
0
Passing a variable (Class) to a sub and using the passed variable to make changes results in the calling routine having its copy adjusted suggesting that BYVAL is not being used for Class objects.

Example Code

```
Class Switch
Public Name
Public IP
End Class

sub Test(byval lsw)
lsw.Name = "From Sub"
end sub

set LSwitch = new Switch
LSwitch.Name = "Outside"
writeline("Name : " & LSwitch.Name)
Test LSwitch
writeline("Name : " & LSwitch.Name)
```
Resulting Output :
```
Name : Outside
Name : From Sub
```
Comments: Hi egooner, Yes, a VBScript object variable holds a _reference_ to the object. The confusing part is that the reference can be passed by value or by reference! You can see the difference by changing `Test` as follows: ``` VB sub Test(byval lsw) set lsw = new Switch lsw.Name = "From Sub" end sub ``` Cheers!

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images