急需解决两个VB计算器的小问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 01:59:33
老师要求我们做VB计算器
但是其实基础什么也没说
所以这简直就是。。。然后问他还说要你自己想。。。恶心的我就。。。那就给个长时间吧。。。他要你2天做出来。。。

还好。。基本搞定。。。现还欠两要求
求大虾们帮忙
一 文本框只允许有12个数字 超过12个要给出提示框
二 实现小数点功能

我的编码
Option Explicit
Dim lastinput As String
Dim Num1 As Double
Dim Num2 As Double
Dim opttype As Integer
Dim result As Double

Private Sub Command1_Click(Index As Integer)
If Text1.Text = "0" Then Text1.Text = ""
Text1.Text = Text1.Text & Index
End Sub

Private Sub Command2_Click()
Text1.Text = "0"
End Sub

Private Sub Command3_Click(Index As Integer)
Num1 = Val(Text1.Text)
Text1.Text = ""
lastinput = "opt"
opttype = Index
End Sub

Private Sub Command4_Click()
Num2 = Val(Text1.Text)
Select Case opttype
Case 0
result = Num1 + Num2
Case 1
result = Num1 - Num2
Case 2
If Val(Num2) = 0 Then

问题1:加入如下代码:Private Sub Text1_Change()
If Len(Text1) > 12 Then
MsgBox "输入错误", 64, "注意"
End If
End Sub
问题2:是的,就是键盘最右边,最下边的那个小数点。操作如下:新建一个按钮,双击此按钮,输入代码:
text1.text=text1.text & "."
就可以了!
我的博客:http://kandisheng.blog.163.com