所以我想制作一个基本的计算器,我遇到了麻烦,
Public Class Form1
Private Numb1
Private Oper
Private Numb2
Private Start As Boolean
Private Ans
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Numb1 = TextBox1.Text
TextBox1.Clear()
TextBox2.Text = Numb1 + "+"
Oper = 1
Start = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Numb2 = TextBox1.Text
TextBox1.Clear()
TextBox2.AppendText(Numb2)
If Oper = 1 Then
Ans = Numb1 + Numb2
TextBox1.Text = Ans
ElseIf Oper = 2 Then
Ans = Numb1 - Numb2
End If
Start = False
End Sub
所以问题是,当我使用计算器添加1 + 2时,它出现在12而不是3.我不知道该怎么做才能实现我不想要彼此旁边的数字,我希望他们添加。
答案 0 :(得分:3)
添加将文本转换为整数所需的数字
Numb1 = CInt(TextBox1.Text)
截至目前,您是concatenating
字符串,因此输出。
此外,截至目前,您对变量的声明被视为对象,因此将其声明为
Private Numb1 as Integer
Numb2