在visual basic中添加和减去

时间:2017-02-01 18:02:04

标签: vb.net

我是Visual Basic 2010 Express的初学者,我需要制作一个基本程序,您可以在textbox1中输入数字,并使用添加或者textbox2添加或减去数字。减去按钮。我的问题是只添加或减去一个数字。例如,如果我添加50,它只显示50,我不能只是继续添加到50,100等。

以下是我的代码:

Public Class Form1
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Subtract.Click
        Dim number1, number2 As Integer 
        number1 = TextBox4.Text 
        number2 = txtVariables.Text 
        TextBox4.Text = number1 - number2 
    End Sub

    Private Sub btnTransfer_Click(sender As System.Object, e As System.EventArgs) Handles btnTransfer.Click
        Dim TextBoxContents As String
        TextBoxContents = txtVariables.Text
        TextBox4.Text = TextBoxContents
        If Val(TextBox4.Text) > 1 Then
            TextBoxContents = Val(TextBox4.Text) + Val(txtVariables.Text)
        Else
            TextBox4.Text = TextBoxContents
        End If
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

使用此

Public Class Form1 Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Subtract.Click
Dim number1, number2 As Integer 
number1 = Convert.toInt32(TextBox4.Text) 
number2 = Convert.toInt32(txtVariables.Text)
TextBox4.Text = (number1 - number2)
End Sub