ByValue

M

mikeFin

I guess this is more a VBA question, than a Visio-specific question, but I
hope someone could help.

Some code I have:

- - - - - -
Public Function func1(var1 as Integer, var2 as Integer)

....
var1=0
....

End Function


Sub Main()

Dim money1 as Integer
Dim resultA as Integer
Dim resultB as Integer
money1 = 20

resultA = func1(money1,60)

resultB = func1(money1,70)

End Sub

- - - - - -

My Problem is that resultB is wrong, because for some reason, money1 is 0
after the first function call.
Shouldn'it stay at 20 ?
I thought, this kind of things might happen, if I passed the argument
ByReference, but thats not what I wanted to do...
I just read again some pages on msdn... it looks like I definied the
variable ByRef. How could I define the variable money1 ByValue ´?
 
P

Paul Herber

I guess this is more a VBA question, than a Visio-specific question, but I
hope someone could help.

Some code I have:

- - - - - -
Public Function func1(var1 as Integer, var2 as Integer)

...
var1=0
...

End Function


Sub Main()

Dim money1 as Integer
Dim resultA as Integer
Dim resultB as Integer
money1 = 20

resultA = func1(money1,60)

resultB = func1(money1,70)

End Sub

- - - - - -

My Problem is that resultB is wrong, because for some reason, money1 is 0
after the first function call.
Shouldn'it stay at 20 ?
I thought, this kind of things might happen, if I passed the argument
ByReference, but thats not what I wanted to do...
I just read again some pages on msdn... it looks like I definied the
variable ByRef. How could I define the variable money1 ByValue ´?

Use ByVal
Is this VBA or VB6?
 
M

mikeFin

I am using the VisualBasic Editor in Visio 2007, so I guess this is VBA.

So if I understand it well, the default is ByRef if I don't specify ByVal or
ByRef??
I thought, ByVal would be the standard.
 
P

Paul Herber

I am using the VisualBasic Editor in Visio 2007, so I guess this is VBA.

So if I understand it well, the default is ByRef if I don't specify ByVal or
ByRef??
I thought, ByVal would be the standard.

It certainly should be! A change to ByRef as the default would
introduce some rather serious errors!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top