用VB设计个简单计算器,个按钮的代码怎么编写啊?急

只有加,减,乘,除,清除,结束就行了... 只有加,减,乘,除,清除,结束就行了 展开
 我来答
百度网友ba88284
2012-04-11 · TA获得超过1521个赞
知道大有可为答主
回答量:1822
采纳率:73%
帮助的人:561万
展开全部
Dim v As Boolean '是否第1次按运算符
Dim s As String '存放上次按的运算符
Dim x As Double '存放第1个操作数
Dim y As Double '存放第2个操作数
Private Sub Command2_Click() 'ok at 11-10-23 +
Call JiSuan("+")
End Sub
Private Sub Command3_Click() 'ok at 11-10-23 -
Call JiSuan("-")
End Sub
Private Sub Command4_Click() 'ok at 11-10-23 *
Call JiSuan("*")
End Sub
Private Sub Command5_Click() 'ok at 11-10-23 /
Call JiSuan("/")
End Sub
Private Sub Command6_Click()
If Form1.Tag = "null" Then
Text1.Text = "0."
Form1.Tag = ""
Else
If InStr(1, Text1.Text, ".") = 0 Then Text1.Text = Text1.Text & "."
End If
Text1.SelStart = Len(Text1.Text)
End Sub
Private Sub Command7_Click() 'ok at 11-10-23 =
Call JiSuan("=")
End Sub
Private Sub Form_Activate()
Me.Caption = "计算器"
End Sub
Private Sub Form_Load() 'ok at 11-10-23
For i = 1 To 9
Command1(i).Caption = i
Next i
v = True
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.SetFocus
If Form1.Tag = "null" Then
Text1.Text = Command1(Index).Caption
Form1.Tag = ""
Else
Text1.Text = Text1.Text & Command1(Index).Caption
End If
Text1.SelStart = Len(Text1.Text)
End Sub
Sub JiSuan(options As String) 'ok at 11-10-23
Form1.Tag = "null"
If v Then '第1次按运算符
x = Val(Text1.Text) '将键入的数存入、
v = Not v
s = options
Else
'根据上次运算符进行计算
y = Val(Text1.Text)
Select Case s 'Sun Rui CopyRight@2010-2012
Case "+"
Text1.Text = x + y
Case "-"
Text1.Text = x - y 'Sun Rui CopyRight@2010-2012
Case "*"
Text1.Text = x * y
Case "/"
If y = 0 Then
MsgBox jiema(3, "DxF76FFFF#DF59FFFFx#9756FFFFx#BB98xFFFF#75xD9FFFF#9xC38FFFF")
Else
Text1.Text = Format(x / y, "0.00######################")
End If
End Select
x = Val(Text1.Text)
s = options
If options = "=" Then
Select Case s 'Sun Rui CopyRight@2010-2012
Case "+"
Text1.Text = x + y 'Sun Rui CopyRight@2010-2012
Case "-"
Text1.Text = x - y
Case "*"
Text1.Text = x * y
Case "/"
If y = 0 Then
MsgBox jiema(3, "DxF76FFFF#DF59FFFFx#9756FFFFx#BB98xFFFF#75xD9FFFF#9xC38FFFF")
Else
Text1.Text = Format(x / y, "0.00######################")
End If
End Select
v = True
End If
End If ' CopyRight@2010-2012
End Sub

'Sun Rui CopyRight@2010-2012
Function jiema(ByVal myao As Long, ByVal codes As String) '解码入口
'CopyRight SunSoft
'Time:2011年6月16日4:11:04
'【功能:根据密钥myao解码codes的内容】
'独立性:daoxu
Dim hut, part3 As String
Dim tos, co2 As Long
strs = Split(codes, "#")
For i = 0 To UBound(strs)
hut = strs(i)
hut = Replace(hut, "x", "")
hut = daoxu(hut)
tos = "&H" + hut
co2 = (tos - myao) / 2
part3 = part3 & Chr(co2)
Next i
jiema = part3
End Function
Function daoxu(ByVal ots As String)
'CopyRight SunSoft
'Time:2011年6月16日4:12:33
'【功能:将字符串倒序】
'独立性:完全
Dim tst As String
Dim wer As Long
tst = ""
For wer = 1 To Len(ots)
tst = tst & Mid(ots, Len(ots) - wer + 1, 1)
Next wer
daoxu = tst
End Function
追问
非常感谢
追答
您应该采纳
tebie386
2012-04-11 · TA获得超过164个赞
知道答主
回答量:198
采纳率:0%
帮助的人:179万
展开全部
用keydown事件。在事件代码里写。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式