Option Explicit
Dim zifu1 As String, zifu2 As String, linshizifu As String * 1, anniu%, num1#, num2#, result#
Private Sub Command1_Click()
linshizifu = Command1.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command10_Click()
linshizifu = Command10.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command11_Click()
num1 = Val(zifu1)
num2 = Val(zifu2)
Select Case anniu
Case 1
result = num1 + num2
Picture1.Print "=" & result
Case 2
result = num1 - num2
Picture1.Print "=" & result
Case 3
result = num1 * num2
Picture1.Print "=" & result
Case 4
If num2 = 0 Then
Picture1.Print " 输入错误.被除数不能为零"
Else
result = num1 / num2
Picture1.Print "=" & result
End If
Case 5
result = num1 ^ num2
Picture1.Print "=" & result
End Select
End Sub
Private Sub Command12_Click()
linshizifu = Command12.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command13_Click()
Picture1.Print Command13.Caption;
anniu = 1
End Sub
Private Sub Command14_Click()
Picture1.Print Command14.Caption;
anniu = 4
End Sub
Private Sub Command15_Click()
Picture1.Print Command15.Caption;
anniu = 3
End Sub
Private Sub Command16_Click()
Picture1.Print Command16.Caption;
anniu = 2
End Sub
Private Sub Command17_Click()
zifu1 = ""
zifu2 = ""
anniu = 0
Picture1.Cls
End Sub
Private Sub Command18_Click()
Dim a%
a = Shell("C:\Program Files\Internet Explorer\IEXPLORE.EXE", 1)
End Sub
Private Sub Command19_Click()
Dim a%
a = Shell("regedit.exe", 1)
End Sub
Private Sub Command2_Click()
linshizifu = Command2.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command20_Click()
Dim a%
a = Shell("C:\Program Files\Outlook Express\msimn.exe", 1)
End Sub
Private Sub Command21_Click()
Dim a%
a = Shell("C:\WINDOWS\explorer.exe", 1)
End Sub
Private Sub Command22_Click()
Dim a%
a = Shell("C:\Program Files\Windows Media Player\wmplayer.exe", 1)
End Sub
Private Sub Command23_Click()
Dim a%
a = Shell("C:\WINDOWS\system32\taskmgr.exe", 1)
End Sub
Private Sub Command24_Click()
Dim a%
a = Shell("C:\WINDOWS\system32\notepad.exe", 1)
End Sub
Private Sub Command25_Click()
Dim a%
a = Shell("C:\WINDOWS\pchealth\helpctr\binaries\msconfig.exe", 1)
End Sub
Private Sub Command26_Click()
linshizifu = Command26.Caption
Picture1.Print linshizifu;
anniu = 5
End Sub
Private Sub Command27_Click()
num1 = Val(zifu1)
If num1 >= 0 Then
result = Sqr(num1)
Picture1.Print "开方=" & result
Else
Picture1.Print " 负数不能开方"
End If
End Sub
Private Sub Command28_Click()
linshizifu = "-"
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command3_Click()
linshizifu = Command3.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command4_Click()
linshizifu = Command4.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command5_Click()
linshizifu = Command5.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command6_Click()
linshizifu = Command6.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command7_Click()
linshizifu = Command7.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command8_Click()
linshizifu = Command8.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Command9_Click()
linshizifu = Command9.Caption
Picture1.Print linshizifu;
If anniu = 0 Then
zifu1 = zifu1 & linshizifu
Else
zifu2 = zifu2 & linshizifu
End If
End Sub
Private Sub Form_Load()
anniu = 0
End Sub
Private Sub 打开cmd_Click()
Dim a%
a = Shell("cmd.exe", 1)
End Sub
————————————————————————————————————————————
上面是代码,由于我刚学VB 2个星期,所以好多不知道怎么弄,书一半还没看到。。。。好多算法不知道怎么实现。。。例如楼上提出的这个问题,负数先点减号不行,我当时也想用减号,但是不知道怎么写程序。。所以就另外加了一个按钮。。。。另外大家也可以从我的这个程序代码中看出,用于计算的只定义了两个变量zifu1和zifu2来记录用户输入,所以多个数同时输入的话就会接在zifu2后面,所以就出问题了。。这个问题我想通过多定义几个变量应该可以解决。。。我会继续学,然后来改进这个计算器。。。。我现在想我的这个计算器的实现算法可能不太好,由于写的时候第一想到的就是这个算法,所以就写了,现在写出来了才发现有好多弊端。。。。我会继续改进。。。也希望各位指点一下本菜鸟。。。。