vb.net计算器编码 vbs计算器代码( 四 )


Dim btn As Button
btn = sender
TextBox1.Text = TextBox1.Text + " " + btn.Text + " "
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
Dim btn As Button
btn = sender
TextBox1.Text = TextBox1.Text + " " + btn.Text + " "
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
'发生错误转移到标号“ErrorPro”指定的行去执行错误处理程序
On Error GoTo ErrorPro
Dim r As Decimal'保存计算结果的变量
Dim t As String = TextBox1.Text'用于保存文本框中的算术表达式
Dim space As Integer = t.IndexOf(" ")'搜索空格位置,如果没有空格,返回值为0
'字符串的取子符方法,第二个参数小于0,则将产生错误号为5的异常,即过程参数不正确
Dim s1 As String = t.Substring(0, space)'通过取子串方法获得第一个运算数
Dim op As String = t.Substring(space + 1, 1)'通过取子串方法获得运算符
Dim s2 As String = t.Substring(space + 3)'通过取子串方法获得第二个运算数
Dim arg1, arg2 As Integer
arg1 = Val(s1) : arg2 = Val(s2)
Select Case op
Case "+" : r = arg1 + arg2
Case "-" : r = arg1 - arg2
Case "*" : r = arg1 * arg2
Case "/" : r = arg1 / arg2
Case Else
MsgBox("输入的运算符有误vb.net计算器编码!")
Exit Sub
End Select
TextBox1.Text = CStr(r)'显示结果
Exit Sub'退出过程
ErrorPro:'错误处理程序块
Select Case Err.Number
Case 6'除数为零时,或运算溢出时的错误号
MsgBox("算术运算溢出!", , "溢出提示")
TextBox1.Focus()
Exit Sub
Case 5' Substring过程的参数不符合要求的错误号
MsgBox("必须输入运算符和第二个运算数!", , "运算数少")
Exit Sub
Case Else
'其它情况显示错误号和错误原因
MsgBox("错误号为"Err.NumberChr(10)Chr(13)"错误原因:"Err.Description)
Exit Sub
End Select
End Sub
End Class
用vb.net做计算器的代码怎么写,其中的控件有radiobutton1234 , 分别代表+-*/,界面代码就不给你贴了,TextBox3显示的是结果 。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1 As Integer = 0
Dim num2 As Integer = 0
Dim result As Integer = 0
Try
num1 = Integer.Parse(TextBox1.Text)
Catch ex As Exception
num1 = 0
End Try
Try
num2 = Integer.Parse(TextBox2.Text)
Catch ex As Exception
num2 = 0
End Try
If RadioButton1.Checked Then
result = num1 + num2
ElseIf RadioButton2.Checked Then
result = num1 - num2
ElseIf RadioButton3.Checked Then
result = num1 * num2
Else
result = num1 / num2
End If
TextBox3.Text = result
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
【vb.net计算器编码 vbs计算器代码】关于vb.net计算器编码和vbs计算器代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读