Results 1 to 3 of 3

Thread: What is ByVal? (ok ok i'm not pro but i need the answer)

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 1999
    Location
    Vilnius, Lithuania
    Posts
    50

    Post

    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
    [email protected]

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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.
    Code:
    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
    [email protected]
    [email protected]


  3. #3
    New Member
    Join Date
    May 1999
    Location
    Boise, Idaho, USA
    Posts
    3

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width