1

Below is an example function with a switch statement, however I'm having a hard time understanding how a function can equal an argument provided?

Function getnumber(value, method) As String
    Dim i, j As Integer
    Dim rtn As String
    j = 0
    Select Case method
    Case 0:


    getnumber = value


    Case 1:
        rtn = ""
        For i = 1 To Len(value)
            If IsNumeric(Mid(value, i, 1)) Then
                j = j + 1
                rtn = rtn & Mid(value, i, 1)
            Else
                If j > 3 Then Exit For
                j = 0
                rtn = ""
            End If
        Next
        If rtn = "" Then getnumber = "" Else getnumber = rtn
    Case Else:
        MsgBox ("Invalid method in getnumber")
    End Select
End Function

"getnumber = value" is really confusing me. Where getnumber is the function and value is an argument of the getnumber function

Any ideas?

2
  • getnumber = value is the return value - the calling code will receive value if it calls getnumber(value, method). Commented Mar 25, 2013 at 11:43
  • 3
    Nothing to do with your question but your function lacks a lot of dimensioning of variables. Dim i, j As Integer should be Dim i As Integer, j As Integer, value and method should be dimensioned too (I think As Variant or As String and As Integer) Commented Mar 25, 2013 at 11:49

1 Answer 1

6

In VBA, you assign the return value of a function with the syntax YourFunctionName = ValueToReturn.

Therefore, getnumber = value simply sets value as the value to be returned from the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.