十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Option Explicit
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、小程序设计、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了永清免费建站欢迎大家使用!
Dim FirstNumber, NumberBuffer As Double'定义数据类型
Dim chr As String
Dim ScaleCodeState As Boolean
Dim ScaleCode As Integer
Dim ScaleSymbol(0 To 7) As String '上面这些DIM都是定义数据类型
Private Sub Init()'==sub过程,实际功能就是清零。把label、FirstNumber、等都初始化
Label1.Caption = "0"
FirstNumber = 0
ScaleCode = 0
ScaleCodeState = False
Label2.Caption = ""
End Sub '==sub过程结束
Private Sub ClearAll_Click() '点击ClearAll按钮
Call Init'执行init过程,就是清零
End Sub
Private Sub Form_Load()'程序启动
Call Init'先清零,下面分别赋值加减乘除
ScaleSymbol(0) = "+"
ScaleSymbol(1) = "-"
ScaleSymbol(2) = "*"
ScaleSymbol(3) = "/"
End Sub
Private Sub NumberKey_Click(Index As Integer)'点击NumberKey按钮,NumberKey是数组控件
chr = Val(Index)
If Left(Label1.Caption, 1) = "0" And Mid(Label1.Caption, 2, 1) "." Then Label1.Caption = Right(Label1.Caption, Len(Label1.Caption) - 1)
'如果label1的第一个字符是0,并且第二个字符不是.,则label1去掉第一个0。这个功能是防止输入了00.9999这样的数,就自动变为0.9999
If Len(Label1.Caption) 20 Then '判断输入的数字长度小于20
If ScaleCodeState = True Then
ScaleCodeState = False
Label1.Caption = ""
End If
Label1.Caption = Label1.Caption + chr
NumberBuffer = Val(Label1.Caption)
End If
End Sub
Private Sub ScaleKey_Click(Index As Integer)'点加减乘除
ScaleCode = Index
FirstNumber = NumberBuffer
ScaleCodeState = True
Label2.Caption = ScaleSymbol(Index)
Label1.Caption = "0"
End Sub
Private Sub Equal_Click()'开始计算
Select Case ScaleCode
Case 0'加
NumberBuffer = FirstNumber + NumberBuffer
Case 1'减
NumberBuffer = FirstNumber - NumberBuffer
Case 2'乘
NumberBuffer = FirstNumber * NumberBuffer
Case 3'除
NumberBuffer = FirstNumber / NumberBuffer
End Select
Label1.Caption = NumberBuffer'显示结果
FirstNumber = NumberBuffer
ScaleCodeState = True
Label2.Caption = ""
End Sub
script language="javascript"
function EnterKeyClick(){
if (window.event.keyCode==13){
event.KeyCode=9;
event.returnValue = false;
//你需要执行的函数
}
}
/script
判断吧,如果点击+按钮,则一个全局变量为1,-按钮,则全局变量为2.以此类推,然后if或case判断哪个数,如果为1,就两个数相加。