btn = sender
TextBox1.Text += btn.Text
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim btn As Button
btn = sender
TextBox1.Text += btn.Text
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Dim btn As Button
btn = sender
'在文本框的Text属性后连接一个空格、本按钮的Text属性值和一个空格
TextBox1.Text = TextBox1.Text + " " + btn.Text + " "
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""'清空文本框
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Dim btn As Button
btn = sender
TextBox1.Text = TextBox1.Text + " " + btn.Text + " "
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
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("输入的运算符有误!")
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计算器中的小数点代码怎么写?谢谢拉在窗口的键盘事件中判断KeyCode就可以了,如:
Private
Sub
窗口_KeyDown(KeyCode
As
Integer,
Shift
As
Integer)
if
KeyCode
=
vbKeyDecimal
then
show.text=show.text
"."
end
if
End
Sub
说明:这里主要是用keyCode来返回小数点的值
vbKeyDecimal
也可以等于
110
这两个是相同的
为什么后面要把它加到一个文本框里面呢,我个人认为 , 你不可能是让他在文本框里直接输入的,如果
推荐阅读
- 模拟建造3游戏名称大全,模拟建造3合集
- java里四种变量代码,java里四种变量代码有哪些
- 用手机相机射击的游戏,相机射击模拟器
- 小程序怎么开通商家收款码,小程序怎么开通商家收款码功能
- 如何用php接收js数据 php接收get请求
- 通话时手机没声音怎么回事,手机通话中没有声音怎么解决
- 阿里个人开发云服务器,阿里云开发平台怎么使用
- 网红小芳直播,网红小芳直播在线观看
- java懂写不出代码 为什么java代码运行不了