如题,哪位大人能帮忙做个VB程序?LZ是高中生,所以只要做个能加减乘除的小计算器就可以了……下面是布置的要求:
要源文件(包括工程文件、窗体文件、模块文件)以及提交可执行文件(exe文件)
急需要!!高考之后那个星期就要的,麻烦谁帮帮忙做一个,咱对程序设计实在是不感冒TAT
联系咱可用扣扣1254【HX】981【HX】545,谢谢了~~~
谢谢各位帮忙^3^
因为家里没有装VB软件【其实就算安装了我也不会做= =为什么理科生一定要学这个!?】每次上课老师说要理解要理解,问题是咱根本不理解……
LZ是住校生,只有周末才能回家,所以要发代码的亲可以直接发到qq邮箱里来,感激不尽~
注意根据代码把所有按键Command名称改过来。窗体见插图。
代码如下:
Option Explicit
Dim operand1, operand2, result As Double
Dim operator As String
Dim flag As Boolean
Dim signflag As Boolean
Private Sub cmdAdd_Click()
'获得第一个操作数,即加数
operand1 = Val(lblScreen.Caption)
'指定运算符为加号
operator = "+"
signflag = True
'清显示屏
lblScreen.Caption = ""
End Sub
Private Sub cmdAdd_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Button = vbLeftButton
End Sub
Private Sub cmdCls_Click()
lblScreen.Caption = ""
operand1 = 0
operand2 = 0
operator = ""
result = 0
End Sub
Private Sub cmdDivide_Click()
'获得第一个操作数,即被除数
operand1 = Val(lblScreen.Caption)
'指定运算符为除号
operator = "/"
'清显示屏
lblScreen.Caption = ""
End Sub
Private Sub cmdEqual_Click()
'从显示屏上获取第二个操作数
operand2 = Val(lblScreen.Caption)
'判断当前运算符
Select Case operator
'如果是加号,则将第一、第二操作数相加
Case "+"
result = operand1 + operand2
Case "-"
result = operand1 - operand2
Case "*"
result = operand1 * operand2
'如果是除号,先判断除数是否为零
Case "/"
If operand2 <> 0 Then
result = operand1 / operand2
Else
MsgBox "除数不能是零!", vbCritical, "错误"
lblScreen.Caption = ""
operand1 = 0
operand2 = 0
Exit Sub
End If
End Select
lblScreen.Caption = result
operand1 = 0
operand2 = 0
operator = ""
End Sub
Private Sub cmdMinus_Click()
'获得第一个操作数,即被减数
operand1 = Val(lblScreen.Caption)
'指定运算符为减号
operator = "-"
'清显示屏
lblScreen.Caption = ""
End Sub
Private Sub cmdMul_Click()
'获得第一个操作数,即乘数
operand1 = Val(lblScreen.Caption)
'指定运算符为乘号
operator = "*"
'清显示屏
lblScreen.Caption = ""
End Sub
Private Sub cmdNum_Click(Index As Integer) '数字键
'声明变量temp,用以获取数字键的索引号
Dim temp As Integer
temp = Index
'将数字键的索引号转变成对应数字显示于显示屏上
lblScreen.Caption = lblScreen.Caption & CStr(temp)
End Sub
Private Sub cmdOpposite_Click()
operand1 = Val(lblScreen.Caption)
operand1 = -operand1
result = operand1
lblScreen.Caption = result
End Sub
Private Sub cmdPoint_Click() '处理小数点
Dim temp As String
If InStr(lblScreen.Caption, ".") Then
Exit Sub
Else
lblScreen.Caption = lblScreen.Caption + "."
End If
End Sub
'键盘事件
Private Sub Form_KeyPress(KeyAscii As Integer)
cmdEqual.SetFocus
If KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Then
lblScreen.Caption = lblScreen.Caption & Chr(KeyAscii)
End If
Select Case Chr(KeyAscii)
Case "+"
cmdAdd_Click
Case "-"
cmdMinus_Click
Case "*"
cmdMul_Click
Case "/"
cmdDivide_Click
Case "."
cmdPoint_Click
Case "="
cmdEqual_Click
End Select
If KeyAscii = vbKeyEscape Then
cmdCls_Click
End If
End Sub
Private Sub Form_Load()
signflag = False
operator = ""
Form1.KeyPreview = True
End Sub