Results 1 to 4 of 4

Thread: Returning values from a function!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    I know how to get a value back from a function.

    Function Hi() as String
    Hi = "Hello"
    End Function


    How do you get two values back with out running the function again?

    Function Hi() as String
    Hi = "Hello"
    Hi = "GoodBye"
    End Function
    Mako Shark
    Great White

  2. #2
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Use an Array:
    Code:
    Function Hi()
    Hi(0)="Hello"
    Hi(1)="Goodbye"
    End Function
    
    Private Sub Form_Load()
    Debug.Print Hi(0)
    Debug.Print Hi(1)
    End Sub
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  3. #3
    Guest
    You can return them in 1 string and use the Split() function to distinguish them.
    Code:
    Function Hi() As Variant
        Hi = Split("Hi,GoodBye", ",")
    End Function
    
    Private Sub Command1_Click()
        Ret1 = Hi(LBound(Hi))    'Get 1st value
        Ret2 = Hi(UBound(Hi))    'Get 2nd value
        Print "Value 1: " & Ret1
        Print "Value 2: " & Ret2
    End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247

    Thumbs up

    Both works great!
    Mako Shark
    Great White

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