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

来源:百度知道 编辑:UC知道 时间:2024/07/07 15:58:00
我要编写一个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)