Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Posts
    183

    Unanswered: returning two variables from procedure

    I have a small calculation procedure, that received a record ID from whereever it is called.

    Until now, it would just return a single variable (currency type) but now I need it to return to separate currency variables.

    Can this be done? or would I have to return an array or something instead?

    Cheers and thanks in advance,

    Trin
    IT squid: networks, servers, firewalls, routers and I dabble a little with SQL-server and Access as well....

  2. #2
    Join Date
    Mar 2004
    Location
    belgium
    Posts
    290
    call the procedure twice like :

    requestedvariable1 = procedurename(ID, 1)
    requestedvariable2 = procedurename(ID, 2)

    adjust the procedure with two if then (else), or use the case statement

    if param2 = 1 then
    ' return requestvariable1
    endif
    if param2 = 2 then
    ' return requestvariable2
    endif

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Trin

    Cunning use of the ByRef passing of parameters means that your functions and subs can effectively return n values

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by pootle flump
    Hi Trin

    Cunning use of the ByRef passing of parameters means that your functions and subs can effectively return n values

    HTH
    Hey professor,

    When are you gonna teach them about variable arguments????
    Back to Access ... ADO is not the way to go for speed ...

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by M Owen
    When are you gonna teach them about variable arguments????
    I thought I would leave it hanging in the air until requested Mike

    Code:
    'ByRef is the default but it is explicit below.
    Sub MultipleReturns(Number As Integer, ByRef PowerOf As Long, ByRef Multiply As Long)
     
        PowerOf = Number ^ 5
        Multiply = Number * 5
     
    End Sub
     
    'Call the proc and use the "return"
    Sub CallMultipleReturns()
     
        Dim PO As Long
        Dim M As Long
     
        Call MultipleReturns(10, PO, M)
     
        Debug.Print "Power of: " & PO & vbCrLf & "Multiplied: " & M
     
    End Sub
    Ta da!

    EDIT -
    BTW Trin

    Paramaters can be passed ByRef or ByVal. ByVal passes a copy of the variable. ByRef passes a pointer to the variable. Changes to a ByRef parameter are seen by the calling app. I like to think of it a bit like emailing a word document to one person and a link to a word document on a share to another. You have access to any changes made by the second person but not the first.

    Professor Poots
    Last edited by pootle flump; 05-15-06 at 09:38.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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