vba ByRef and ByVal Variable Declaration

12-22-2006, 02:33 AM
Hi VBA Gurus
couls anyone kindly explain to me what this code does if suppliied with the following values:1,2,3,4,5

'example on passing arguments byref declaration
Function test2(a As Integer)
a = a - 2

If a = 0 Or a < 0 Then
test2 = 2
Exit Function
End If
test2 = test2(a) * (a + 10)
End Function
Sub calc2()
Dim aa As Integer
aa = InputBox("enter integer ", "integer", 0)
MsgBox aa
MsgBox test2(aa)
MsgBox aa
End Sub

i can not seem to figure out how the outcomes are being calculated


12-22-2006, 04:49 AM
Sorry, this sounds like a homework assignment to me...

Why don't you:

Try running (or even better, stepping through) the code and seeing what happens to the variables, using the Locals window
Read about Byval and Byref in the help files

12-22-2006, 06:42 AM
thanks friend
i am actually teaching myself Access VBA.
I last had an assignment ten years ago.
been out of programming from the cobol and pascal days.
Just stepped thru the code as suggested and i am now able to see what is happening.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum