Results 1 to 4 of 4

Thread: [RESOLVED] newbie help

  1. #1

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Resolved [RESOLVED] newbie help

    Hi
    I'm newbie in visual basic. I'm having problem in understanding functions (byval & byref). I have surfed on the internet but i found no useful link for that. Will anyone provide me some links please..



    Thanks in advance.

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: newbie help

    ByVal means to pass by value. This means a copy of the variable is sent to the function. ByRef means pass by reference. A "pointer" to the variable is sent to the function, so if you assign a new value to the passed parameter in the called function, the variable from the calling function is changed, too. Because ByRef parameters are just "pointers", the variable datatype must be an exact match. When you pass variables ByVal the dataype doesn't have to match because VB does implicit coercion.

  3. #3

    Thread Starter
    Hyperactive Member Aash's Avatar
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    491

    Re: newbie help

    Thanks for the reply Ellis
    So in Byval values can be changed and in Byref can't?
    can both Byref and Byval be used in the same user-defined function??
    like this..
    Code:
    Private function Add(Byref a as integer, Byval b as integer)
    if so, will u explain it?

  4. #4
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: newbie help

    All values can be changed, the difference is that changes to ByVal parameters get discarded once the function ends while changes to ByRef parameters are saved even after the function ends.

    Yes, both types can be used in the same function.

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