Ask a questionAsk a question
 

Answervisual basic

  • Wednesday, November 04, 2009 9:46 AMRosalind Gray Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Write a program that allows users to specify two numbers and then adds,

    subtracts or multiplies them when the user clicks on the appropriate button.

    The output should give the arithmetic performed and the result.


    Rosalind Gray

Answers

  • Wednesday, November 04, 2009 11:11 AM•.trujade.• Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    new project.. 3 textboxes, 4 buttons.

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Button1.Text = "add"
            Button2.Text = "subtract"
            Button3.Text = "multiply"
            Button4.Text = "divide"
        End Sub
    
        '--  allow only nummeric characters in BOTH textboxes from one event
        Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles TextBox1.KeyPress, TextBox2.KeyPress
            Select Case e.KeyChar
                Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", vbBack
                    Exit Sub
                Case Else
                    e.Handled = True
            End Select
        End Sub
    
        '-- add
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox3.Text = CInt(TextBox1.Text) + CInt(TextBox2.Text)
        End Sub
    
        '-- subtract
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            TextBox3.Text = CInt(TextBox1.Text) - CInt(TextBox2.Text)
        End Sub
    
        '-- multiply
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            TextBox3.Text = CInt(TextBox1.Text) * CInt(TextBox2.Text)
        End Sub
    
        '-- divide
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            TextBox3.Text = CInt(TextBox1.Text) / CInt(TextBox2.Text)
        End Sub
    
    End Class
    
    

    •.' trujade '.•

All Replies

  • Wednesday, November 04, 2009 9:51 AMbdbodger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is that a question ? I don't get it if it is .
    coding for fun Be a good forum member mark posts that contain the answers to your questions or those that are helpful
    Please format the code in your posts with the button . Makes it easier to read .
  • Wednesday, November 04, 2009 11:11 AM•.trujade.• Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    new project.. 3 textboxes, 4 buttons.

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Button1.Text = "add"
            Button2.Text = "subtract"
            Button3.Text = "multiply"
            Button4.Text = "divide"
        End Sub
    
        '--  allow only nummeric characters in BOTH textboxes from one event
        Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
        Handles TextBox1.KeyPress, TextBox2.KeyPress
            Select Case e.KeyChar
                Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", vbBack
                    Exit Sub
                Case Else
                    e.Handled = True
            End Select
        End Sub
    
        '-- add
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox3.Text = CInt(TextBox1.Text) + CInt(TextBox2.Text)
        End Sub
    
        '-- subtract
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            TextBox3.Text = CInt(TextBox1.Text) - CInt(TextBox2.Text)
        End Sub
    
        '-- multiply
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            TextBox3.Text = CInt(TextBox1.Text) * CInt(TextBox2.Text)
        End Sub
    
        '-- divide
        Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            TextBox3.Text = CInt(TextBox1.Text) / CInt(TextBox2.Text)
        End Sub
    
    End Class
    
    

    •.' trujade '.•