PDA

Click to See Complete Forum and Search --> : What is ByVal? (ok ok i'm not pro but i need the answer)


casparas
Jan 12th, 2000, 03:25 AM
So What is ByVal?

I'm just beginer in VB so i know practicaly nothing in it.

By the way thanks for everyone who answered my previous posts and who will answer this one.

------------------
-casparas

novice programer
casparas@metacrawler.com

Aaron Young
Jan 12th, 2000, 03:38 AM
ByVal means To Pass By Value, meaning you you pass something ByVal you are passing the Value of the Variable not a Pointer to the Variable itself, ie.

Private Sub Command1_Click()
Dim iTemp As Integer
iTemp = 2
Call Add2(iTemp)
Debug.Print iTemp
End Sub

Private Sub Add2(ByVal X As Integer)
X = X + 2
End Sub

Calling this code would always Print "2" in the Debug Window.

If you modify the Add2 Routine to be ByReference, it would Print "4".


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

Roger Eagans
Jan 12th, 2000, 03:56 AM
One other thing to note. ByRef is the VB default way of passing variable. If you don't specify, it will be ByRef.

Roger Eagans