Results 1 to 3 of 3

Thread: passing an address to a function

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Location
    Clark County Washington
    Posts
    6
    Quick question that should be easy for the experienced. I am trying to pass a variable's adderss as a parameter of a function. How do I write that in VB code. In C++ I would just put niftyfunciton(&variable) but the & in VB is for concatination. Whats the notation for passing a reference in VB?

  2. #2
    Guest
    VB passes everything by reference by default. You can add the ByRef keyword in the declaration if you want to be explicit.

    John

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I'm not entirely sure what you're trying to do.

    you can pass a variable ByRef to a Function by specifying it in the Declaration

    Code:
    Private Sub AddOne(ByRef Number as Long)
    
        Number = Number + 1
    
    End Sub
    will add one to what's stored in the variable passed to it.

    If you want a Pointer to a Variable you can use
    VarPtr(MyVar) which returns a long pointer to MyVar, I'ts pretty useless in VB Though unless you wan't to do some really wierd stuff with APIs that you could do without pointers.

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