Consulting

Results 1 to 3 of 3

Thread: vba add

  1. #1
    Banned VBAX Regular
    Joined
    Jul 2018
    Posts
    9
    Location

    vba add

    Sub phoenixmoto()
        With UserForm1
           .wow.Value = True
            With .comb
                .AddItem "addition"
                .AddItem "subtraction"
            End With
                .comb.Value = "subtraction"
                
                .TextBox1.Value = 10
                .TextBox2.Value = 20
                .TextBox3.Value = 30
                .Show
        End With
    Unload UserForm1
    End Sub
    
    
    
    Private Sub cancel_Click()
    hide
    End Sub
    
    
    Private Sub ok_Click()
        Dim a As Variant, b As Variant, c As Variant
        If TextBox1.Value = "" Then
        MsgBox "a field is empty"
        Exit Sub
        End If
        If TextBox2.Value = "" Then
        MsgBox "b field is empty"
        Exit Sub
        End If
        If TextBox3.Value = "" Then
        MsgBox "c field is empty"
        Exit Sub
        End If
        
        a = TextBox1.Value
        b = TextBox2.Value
        c = TextBox3.Value
        
        If wow.Value = True Then
        Select Case comb
            Case "addition"
                Call ad(a, b, c)
            Case "subtraction"
                Call minus(a, b, c)
        End Select
        End If
    hide
    End Sub
    
    
    Sub ad(a As Variant, b As Variant, c As Variant)
    ThisDocument.TextBox10.Value = amrit(a, b, c)
    End Sub
    Sub minus(a As Variant, b As Variant, c As Variant)
    ThisDocument.TextBox10.Value = sam(a, b, c)
    End Sub
    Public Function amrit(a As Variant, b As Variant, c As Variant) As Variant
    amrit = (a + b + c)
    End Function
    Public Function sam(a As Variant, b As Variant, c As Variant) As Variant
    sam = (a - b - c)
    End Function
    here in this code function sam works fine and delivers -40 as answer but function amrit does concatination(102030) instead of sum(i.e 60)
    how + symbol is working like &
    Last edited by Aussiebear; 12-13-2018 at 11:48 PM. Reason: Wrapped code with tags

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    phoenixmoto: Kindly post your threads in the forum relevant to whatever the topic is. Moreover, this thread is nothing more than a discussion you previously started in the Announcement forum - which quite obviously is not the correct forum for threads of this kind. I previously moved your threads to the correct forum. This time, I'm closing it instead. I trust you'll get the message.


    Furthermore, when posting code, use the code tags, indicated by the # button on the posting menu. Without them, your code loses whatever structure it had.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted at: http://www.vbaexpress.com/forum/show...?64008-vba-add
    Please read VBA Express' policy on Cross-Posting in item 3 of the rules: http://www.vbaexpress.com/forum/faq...._new_faq_item3
    Since you have persistently ignored that rule, you account here is terminated.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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