当我点击“+”时如何制作唱他们加两个数字。 [英] How to make when I am click on "+" sing they add two number .
本文介绍了当我点击“+”时如何制作唱他们加两个数字。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
' 数字在textbox1中声明。使用+和两个数字相加=唱
公开 类 Form1
< span class =code-keyword> Dim num1 As Double
< span class =code-keyword> Dim num2 As Double
< span class =code-keyword> Dim operation As Double
< span class =code-keyword> Dim oprationsec As Boolean = False
Dim ans As Double
私有 Sub Form1_Load( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 MyBase .Load
结束 Sub
私有 Sub Button2_Click( ByVal sender 正如系统。对象, ByVal e As System.EventArgs)句柄 Button2.Click
如果 TextBox1.Text< > 0 然后
TextBox1.Text + = 1
否则
TextBox1.Text = 1
结束 如果
结束 Sub
私有 Sub Button3_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button3.Click
如果 TextBox1.Text <> 0 然后
TextBox1.Text + = 2
否则
TextBox1.Text = 2
结束 如果
结束 Sub
私有 Sub Button4_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button4.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 3
否则
TextBox1.Text = 3
结束 如果
结束 Sub
私有 Sub Button5_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button5。点击
如果 TextBox1.Text <> 0 然后
TextBox1.Text + = 4
否则
TextBox1.Text = 4
结束 如果
结束 Sub
私有 Sub Button6_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button6.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 5
否则
TextBox1.Text = 5
结束 如果
结束 Sub
私有 Sub Button7_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button7.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 6
否则
TextBox1.Text = 6
结束 如果
结束 Sub
私有 Sub Button8_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button8.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 7
否则
TextBox1.Text = 7
结束 如果
结束 Sub
私有 Sub Button9_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button9.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 8
否则
TextBox1.Text = 8
结束 如果
结束 Sub
私有 Sub Button10_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button10。点击
如果 TextBox1.Tex t<> 0 然后
TextBox1.Text + = 9
否则
TextBox1.Text = 9
结束 如果
结束 Sub
私有 Sub Button1_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> 0 然后
TextBox1.Text + = 0
结束 如果
结束 Sub
私有 Sub Button16_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 Button16.Click
TextBox1.Text = 0
End Sub
私有 Sub Button13_Click( ByVal sender 作为系统。对象, ByVal e 正如 System.EventArgs)句柄 Button13.Click
num1 = TextBox1.Text
TextBox1.Text = 0
oprationsec = True
operation = 1
结束 Sub
私有 Sub Button14_Click( ByVal 发件人作为系统。对象, ByVal e As System.EventArgs)句柄 Button14.Click
num1 = TextBox1.Text
TextBox1。 Text = 0
oprationsec = True
operation = 2
结束 Sub
私有 Sub Button12_Click(< span class =code-keyword> ByVal sender As System。 Object , ByVal e As System.EventArgs) Handles Button12。单击
num1 = TextBox1.Text
TextBox1.Text = 0
oprationse c = True
operation = 3
结束 Sub
私有 Sub Button11_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 Button11.Click
num1 = TextBox1.Text
TextBox1.Text = 0
oprationsec = True
operation = 4
结束 Sub
私人 Sub Button15_Click( ByVal sender As System。 Object , ByVal e As System.EventArgs)句柄 Button15。点击
如果 oprationsec = True 或 TextBox1.Text<> IsNumeric(TextBox1.Text> 0 )然后
num2 = TextBox1.Text
如果 operation = 1 那么
TextBox1.Text = num1 + num2
ElseIf operation = 2 然后
TextBox1.Text = num1 - num2
ElseIf operation = 3 然后
TextBox1.Text = num1 / num2
ElseIf operation = 4 然后
TextBox1.Text = num1 * num2
< span class =code-keyword> Else
如果 num2 = 0 那么
TextBox1.Text = 错误
结束 如果
结束 如果
oprationsec = False
否则
TextBox1.Text = 错误
结束 如果
结束 Sub
私有 Sub Button18_Click( ByVal 发件人 As S. ystem。对象, ByVal e 作为系统.EventArgs)句柄 Button18。点击
如果 不(TextBox1.Text.Contains( 。))然后
TextBox1.Text + = 。
结束 如果
结束 Sub
私有 Sub Button17_Click( ByVal sender As System。对象, ByVal e As System.EventArgs)句柄 Button17.Click
num1 = TextBox1.Text
TextBox1.Text = < span class =code-string> 0
oprationsec = True
operation = 1
结束 Sub
结束 类
我尝试了什么:
首先在+之后添加数字添加第二个数字,然后点击=我得到了加法,但是当如何仅通过+来加法时,
解决方案
从文本框中读取两个值,并将它们转换为数字:
Dim x As Double
如果 不 Double .TryParse(TextBox1.Text,x)然后
...报告编号问题 to user ...
返回
结束 如果
Dim y As < span class =code-keyword> Double
如果 不 Double .TryParse(TextBox1.Text,y)然后
...报告编号问题至用户...
返回
结束 如果
Dim 结果 As Double = x + y
textBoxResult.text = result.ToString()
'numbers are declare in textbox1 .the addition of two numbers using + and = sing
Public Class Form1
Dim num1 As Double
Dim num2 As Double
Dim operation As Double
Dim oprationsec As Boolean = False
Dim ans As Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
TextBox1.Text = "0"
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
num1 = TextBox1.Text
TextBox1.Text = "0"
oprationsec = True
operation = 1
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
num1 = TextBox1.Text
TextBox1.Text = "0"
oprationsec = True
operation = 2
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
num1 = TextBox1.Text
TextBox1.Text = "0"
oprationsec = True
operation = 3
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
num1 = TextBox1.Text
TextBox1.Text = "0"
oprationsec = True
operation = 4
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If oprationsec = True Or TextBox1.Text <> IsNumeric(TextBox1.Text > 0) Then
num2 = TextBox1.Text
If operation = 1 Then
TextBox1.Text = num1 + num2
ElseIf operation = 2 Then
TextBox1.Text = num1 - num2
ElseIf operation = 3 Then
TextBox1.Text = num1 / num2
ElseIf operation = 4 Then
TextBox1.Text = num1 * num2
Else
If num2 = 0 Then
TextBox1.Text = "Error"
End If
End If
oprationsec = False
Else
TextBox1.Text = "Error"
End If
End Sub
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
num1 = TextBox1.Text
TextBox1.Text = "0"
oprationsec = True
operation = 1
End Sub
End Class
What I have tried:
first add number after "+" sing after add second number and then click on "=" i got addition but when how to make addition by only only "+" sing
解决方案
Read the two values from your textboxes, and convert them to numbers:
Dim x As Double If Not Double.TryParse(TextBox1.Text, x) Then ... report number problem to user ... Return End If Dim y As Double If Not Double.TryParse(TextBox1.Text, y) Then ... report number problem to user ... Return End If Dim result As Double = x + y textBoxResult.text = result.ToString()
这篇关于当我点击“+”时如何制作唱他们加两个数字。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文