用VB编写计算器,控件都弄好了,求代码!

求代码!!!

给你一个思路吧,毕竟是学习,直接看代码还不如看思路,然后自己出代码好。
界面设计方面,图中的文本框做显示屏使用,Name设为:Text1,
按钮设为一个控件数组Cmd(),
0-9用Cmd(0)-Cmd(9)表示。
小数点用Cmd(10)表示,
加减乘除分别用Cmd(11)-Cmd(14)表示,
等于用Cmd(15)表示
其他的自行决定。
定义一个变量TxtNumber,用于保存第一个因数(计算用)
定义一个变量TxtFh用于储存运算符号
下面是部分代码,不懂再追问。
Private Sub Cmd(index as integer)_Click()
Select Case index ‘index代表我们按下的按钮
Case 0 to 9
Text1=Text1 & Cmd.Caption
Case 10 ’小数点的处理,在第一个前加上“0”
If Texe1="" Then
Text1="0."
Else
Text1= Text1 & "."
End if
Case 11 to 14
If txtNumber=“”Then ‘检查是否按过符号键
txtNumber=Text1
Text1=""
txtFh=Cmd.Caption
Else ’按过符号键就先将前面的数进行计算
txtNumber= Js(txtNumber,Val(Text1),txtFh)
Text1=""
txtFh=Cmd.Caption
End If
Case 15 ‘计算结果,并显示
If txtFh<>" " Then
Text1=Js(txtNumber,Val(Text1),txtFh)
txtNumber=""
ElseIf Text1="" Then
Text1=txtNumber
txtNumber=""
End If
Case 16
...........................
End Select
End Sub

下面代码用于计算:
private Function Js(Num1 as integer , Num2 as integer , Fh as String )
Select Case Fh
Case "+"
Js=Num1+Num2
Case "-"
Js=Num1-Num2
Case "x"
Js=Num1 * Num2
Case "/"
Js=Num1/Num2
End Select
End Function
暂时先打这些代码,其余的望楼主举一反三,不懂再问
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

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