Return Values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    Return Values

    I'm having a problem with returning values from a function.

    No matter what I do I can't return values from another function to store in a variable. Any help much appreciated!

    Say I have:
    Code:
    Public Sub MainFunc()
      result = test "param1","param2"
    End Sub
    
    Private Sub test(param1In,param2In)
      {return value}
    End Sub
  • ziycon
    Contributor
    • Sep 2008
    • 384

    #2
    Ok, I've gotten a bit further, I release I should have been using Function instead of Sub, can someone tell me the difference?

    I've changed the code to be like below but its still crashing out at the function call?

    Code:
    Public Function MainFunc(param1In,param2In)
      result = test(param1In,param2In)
    
      Console.Write result
    End Function
      
    Private Function test(param1In,param2In)
      Dim answer
    
      answer = param1In + param2In
    
      Set test = answer
    End Function

    Comment

    • vb5prgrmr
      Recognized Expert Contributor
      • Oct 2009
      • 305

      #3
      Function = As Something...
      Code:
      Private Function MyFunction (MyInput As String) [B]As String[/B]
      MyFunction = MyInput
      End Function


      Good Luck

      Comment

      • ziycon
        Contributor
        • Sep 2008
        • 384

        #4
        I'm slightly confused, I understand the example you gave, just not 100% sure how it would handle multiple parameters?

        Code:
        Private Function test(param1In,param2In)
          Dim answer
          answer = param1In + param2In
          test = answer
        End Function

        Comment

        • ziycon
          Contributor
          • Sep 2008
          • 384

          #5
          Got it working, thanks for your help.

          Comment

          Working...