vb.net手输计算器 vbs写计算器( 四 )


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(" ")'搜索空格位置,如果没有空格vb.net手输计算器,返回值为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做一个简单的计算器,当然是做的越高级越好,不要生成的EXE 。连程序一起发过来 。采纳追加500分!计算机光要加减乘除的那种吗?
先在窗口添加一个textbox文本框名字是textbox1,再添加一个标签,属性text:(为一个空格)名字是label1,再加一个textbox文本框 , 名字是textbox2,加标签 , 名字是label2,属性text:“=”(引号不算),在后面加一个文本框,名字为textbox3.下一行添加五个按钮,名字分别是Button1(属性text:加),Button2(属性text:减).……最后一个是,清空,按钮
双击Button1,输入代码:dim a,b,c as single(回车!)a=textbox1.text(!)b=textbox2.text(!)a+b=c(!),textbox3=c(!)
后面分别点击不同的按钮 , 把“+”改成“-”,“*”“/”行了
双击最后按钮输入textbox1=""(!)textbox2=""(!)textbox3=""就ok了 , 累死我了呵呵(?。┍硎净爻蛋?

推荐阅读