+ Reply to Thread
Results 1 to 6 of 6

Returning a variant from a function

  1. #1
    Registered User
    Join Date
    02-16-2004
    Posts
    10

    Returning a variant from a function

    Hi Guys,

    This will probably make me sound really thick but can someone help me out.

    I'm calling a function to display an input box and I want to return a numeric string to the calling function so it can be evaluated and work out where to go next.

    Can someone help please.

    Thanks,
    Richard.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Richard,

    The return value from the InputBox is a String that was input by the user.

    result = InputBox("Input Numbers Below")

    Result equals what the user input or an empty string if they click the Close Box or Cancel. I am not sure this what your question is about. If you need further help, repost with more information.

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    02-16-2004
    Posts
    10
    Hi Leith Ross,

    This is what I'm trying to figure out...

    Private Sub cmdProcessExport2_Click()

    Call dateImport --from here I want to call the function

    If returnCode = 1 then -- return code to come from function below
    do this
    Else
    do something else
    End if

    End Sub

    ________________________________________________

    Private Function dateImport()

    Message = "Please enter the date of the file you want to import"
    Title = "Enter File Date"
    Style = vbYesNo
    Response = InputBox(Message, Title)

    If Len(Response) > 6 Then
    do some processing

    return to cmdProcessExport2 sending return string
    End if



    End Function

    Does this make sense?

    Thanks for your help.

    Richard.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Richard,

    Makes perfect sense. You simplely need to assign the return value to the function. By default, all functions use a variant as the return value, however, you can specifiy what you want to return. I've made the change in your code in bold.

    Private Function dateImport()

    Message = "Please enter the date of the file you want to import"
    Title = "Enter File Date"
    Style = vbYesNo
    Response = InputBox(Message, Title)

    If Len(Response) > 6 Then
    do some processing

    return to cmdProcessExport2 sending return string
    dateImport = Response

    End if

    This will return your input value to the calling routine cmdProcessExport2. However, somewhere in your calling routine you need to set a variable equal to the function name.

    ReturnVariable = dateImport


    That should do it,
    Leith Ross

  5. #5
    Registered User
    Join Date
    02-16-2004
    Posts
    10
    Excellent, thanks for the help... it works a treat!!!

    Now I do feel stupid

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Richard,

    Gald to help. Have a happy St. Patrick's day!

    Erin go braugh! (Gaelic - Ireland forver!)

    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1