how to return a value from a function in VB

vb6 Grenada
  • 14 years ago

    i want the details of how to return values from a function

    thank you in advance

  • 14 years ago
  • 14 years ago
    Hi Harish

     Here I am giving an example for u.

     Private Sub Command1_Click()
    Dim intTotal As Integer

        intTotal = fncCalculation(20, 10, "add")
        MsgBox "Addition of 20 and 10 is : " & intTotal
        intTotal = fncCalculation(20, 10, "sub")
        MsgBox "Subtraction of 20 and 10 is : " & intTotal
        intTotal = fncCalculation(20, 10, "mul")
        MsgBox "Multiplication of 20 and 10 is : " & intTotal
        intTotal = fncCalculation(20, 10, "div")
        MsgBox "Division of 20 and 10 is : " & intTotal
    End Sub
    Private Function fncCalculation(num1 As Integer, num2 As Integer, strOption As String) As Integer
    On errot GoTo ErrFunction
        Select Case UCase(strOption)
            Case "ADD"
                fncCalculation = num1 + num2
            Case "SUB"
                fncCalculation = num1 - num2
            Case "MUL"
                fncCalculation = num1 * num2
            Case "DIV"
                fncCalculation = num1 / num2
            Case Else
                fncCalculation = 0
        End Select
        Exit Function
       
    ErrFunction:
            fncCalculation = 0
    End Function


    I hope u can get the Logic for how to use the function

    Good  Luck


    Regards
    Hari K
















































  • 14 years ago

    thank you i got it

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare