vb编写计算器加减乘除怎么弄?

我要编写一个vb计算器,才发现我们没学控件组。比较郁闷。
我先是建立11个按钮分别命名为0-9+“.”
名字都弄成cmddigit
然后将index的属性设为0-9 10为"."
数字按钮的代码我在书上抄到的.
为private sub cmddigit_click(index as integer)
static blndot as boolean
dim strkey$
strkey=cmddigit(index).caption
if strkeyu ="." then if not blndot then blndot = true Else exit sub
if not blndigit then text1.text=""
text1.text=text1.text & strkey
blndigit = ture
End sub
这是我在书上抄到的数字键的代码程序,稍微能看明白点但还是不太会用这些控件组,请帅哥如果明白 把这些话每句意思都告诉一下我吧嘿嘿
现在请帅哥帮我编一下 backspace ce c + - * / = 1 /x sqrt % 还有就是正负号。的代码。
谢谢了

我好不容易才弄出来的,你看着给分吧。用复制粘贴的方法把Cmddigit创建到(20)(也就是21个按钮)。
代码如下。
===========================
Option Explicit
Dim x As Integer
Dim num As Double
Private Sub cmddigit_click(index As Integer)
Select Case index
Case Is < 11
If InStr(1, Text1.Text, ".") = 0 Then
Text1.Text = Text1.Text + cmddigit(index).Caption
Else
If index <> 10 Then Text1.Text = Text1.Text + cmddigit(index).Caption
End If
Case 11
Text1.Text = Left(Len(Text1.Text) - 1, Text1.Text)
Case 12
Text1.Text = ""
Text2.Text = ""
Case 13
If InStr(1, Text1.Text, "-") = 1 Then
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
Else
Text1.Text = "-" & Text1.Text
End If
Case 18
Text2.Text = Str(1 / Text1.Text)
Case 19
Text2.Text = Str(Sqr(Text1.Text))
Case 20
Select Case x
Case 14
Text2.Text = num + CDbl(Text1.Text)
Case 15
Text2.Text = num - CDbl(Text1.Text)
Case 16
Text2.Text = num * CDbl(Text1.Text)
Case 17
Text2.Text = num / CDbl(Text1.Text)
End Select
Text1.Text = ""
Case Else
num = CDbl(Text1.Text)
x = index
Text1.Text = ""
End Select
End Sub

Private Sub Form_Load()
cmddigit(10).Caption = "."
cmddigit(11).Caption = "Backspace"
cmddigit(12).Caption = "CE"
cmddigit(13).Caption = "+/-"
cmddigit(14).Caption = "+"
cmddigit(15).Caption = "-"
cmddigit(16).Caption = "*"
cmddigit(17).Caption = "/"
cmddigit(18).Caption = "1/x"
cmddigit(19).Caption = "Sqrt"
cmddigit(20).Caption = "="
Text1.Text = ""
Text2.Text = ""
End Sub
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网