Public fir As Double
Public p As String
Public sec As Double
Private Sub callc_click()
strWinDir = Environ("windir")
Shell (strWinDir & "\system32\calc.exe"), vbNormalFocus
End SubPrivate Sub Form_Load()
Form2.Show
Form1.Hide
End SubPrivate Sub how_Click()
Dim value As Integer
value = MsgBox("±¾³ÌÐòÓÃVB6.0д³É£¬Ëü²»½ö¿ÉÒÔ½øÐÐÒ»°ãµÄÊýÖµ¼ÆË㣬»¹¿ÉÒÔÏÔʾÈÕÆÚ,Ä㻹¿ÉÒÔµ÷ÓÃWindows×Ô´øµÄ¼ÆËãÆ÷£¬¡°¹ØÓÚ¡±Öл¹¼¯³Éʱ¼äÈÕÆÚÏÔʾºÍÃë±í¹¦ÄÜ¡£", 0, "˵Ã÷")End Sub
Private Sub about_Click()
form3.Show
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
Text1.Text = "7"
Else
Text1.Text = Text1.Text + "7"
End If
End SubPrivate Sub Command10_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "/"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command11_Click()
If Text1.Text = "" Then
Text1.Text = "1"
Else
Text1.Text = Text1.Text + "1"
End If
End SubPrivate Sub Command12_Click()
If Text1.Text = "" Then
Text1.Text = "2"
Else
Text1.Text = Text1.Text + "2"
End If
End SubPrivate Sub Command13_Click()
If Text1.Text = "" Then
Text1.Text = "3"
Else
Text1.Text = Text1.Text + "3"
End IfEnd SubPrivate Sub Command14_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "-"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command15_Click()
If Text1.Text = "" Then
MsgBox "ûÓÐÊý¾Ý¿ÉÇå³ý£¡", , "¾¯¸æ´°¿Ú"
Exit Sub
Else
Text1.Text = ""
End If
End SubPrivate Sub Command16_Click()
If Text1.Text = "" Then
Text1.Text = "0"
Else
Text1.Text = Text1.Text + "0"
End If
End SubPrivate Sub Command17_Click()
If InStr(Text1.Text, ".") = 0 Then
If Text1.Text = "" Then
Text1.Text = "."
Else
Text1.Text = Text1.Text + "."
End If
End If
End SubPrivate Sub Command18_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "+"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command19_Click()
If p = "jc" Then
fir = Val(Text1.Text)
Else
sec = Val(Text1.Text)
End If
If Text1.Text = "" And p <> "!" Then
MsgBox "Íü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
Else
Select Case p
Case "+"
Text1.Text = Str$(fir + sec)
Case "-"
Text1.Text = Str$(fir - sec)
Case "*"
Text1.Text = Str$(fir * sec)
Case "/"
If sec = 0 Then
MsgBox "Áã²»ÄÜ×ö³ýÊý£¡", 16, "¾¯¸æ´°¿Ú"
Exit Sub
End If
Text1.Text = Str$(fir / sec)
Case "%"
If sec = 0 Then
MsgBox "Áã²»ÄÜ×ö³ýÊý£¡", 16, "¾¯¸æ´°¿Ú"
Exit Sub
End If
If Int(fir) <> fir Or Int(sec) <> sec Then
MsgBox "Ö»ÓÐÕûÊý²ÅÄܽøÐÐÕû³ýÔËËã", 16, "¾¯¸æ´°¿Ú"
Exit Sub
Else
Text1.Text = Str$(fir \ sec)
End If
Case "cf"
Text1.Text = Str$(fir ^ sec)
Case "kf"
Text1.Text = Str$(fir ^ (1 / sec))
End Select
End If
End Sub
Private Sub Command20_Click()
yer = Year(Now)
mnth = Month(Now)
dy = Day(Now)
Select Case Weekday(Now)
Case 1
wkd$ = "ÈÕ"
Case 2
wkd$ = "Ò»"
Case 3
wkd$ = "¶þ"
Case 4
wkd$ = "Èý"
Case 5
wkd$ = "ËÄ"
Case 6
wkd$ = "Îå"
Case 7
wkd$ = "Áù"
End Select
Text1.Text = Str$(yer) + "Äê" + Str$(mnth) + "ÔÂ" + Str$(dy) + "ÈÕ ÐÇÆÚ" + wkd$
End SubPrivate Sub Command3_Click()
If Text1.Text = "" Then
Text1.Text = "9"
Else
Text1.Text = Text1.Text + "9"
End If
End Sub
Private Sub Command4_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "/"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command5_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "kf"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command6_Click()
If Text1.Text = "" Then
Text1.Text = "4"
Else
Text1.Text = Text1.Text + "4"
End IfEnd SubPrivate Sub Command7_Click()
If Text1.Text = "" Then
Text1.Text = "5"
Else
Text1.Text = Text1.Text + "5"
End IfEnd SubPrivate Sub Command8_Click()
If Text1.Text = "" Then
Text1.Text = "6"
Else
Text1.Text = Text1.Text + "6"
End IfEnd SubPrivate Sub Command9_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "*"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End IfEnd Sub
Private Sub Command2_Click()
If Text1.Text = "" Then
Text1.Text = "8"
Else
Text1.Text = Text1.Text + "8"
End IfEnd Sub
Public p As String
Public sec As Double
Private Sub callc_click()
strWinDir = Environ("windir")
Shell (strWinDir & "\system32\calc.exe"), vbNormalFocus
End SubPrivate Sub Form_Load()
Form2.Show
Form1.Hide
End SubPrivate Sub how_Click()
Dim value As Integer
value = MsgBox("±¾³ÌÐòÓÃVB6.0д³É£¬Ëü²»½ö¿ÉÒÔ½øÐÐÒ»°ãµÄÊýÖµ¼ÆË㣬»¹¿ÉÒÔÏÔʾÈÕÆÚ,Ä㻹¿ÉÒÔµ÷ÓÃWindows×Ô´øµÄ¼ÆËãÆ÷£¬¡°¹ØÓÚ¡±Öл¹¼¯³Éʱ¼äÈÕÆÚÏÔʾºÍÃë±í¹¦ÄÜ¡£", 0, "˵Ã÷")End Sub
Private Sub about_Click()
form3.Show
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
Text1.Text = "7"
Else
Text1.Text = Text1.Text + "7"
End If
End SubPrivate Sub Command10_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "/"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command11_Click()
If Text1.Text = "" Then
Text1.Text = "1"
Else
Text1.Text = Text1.Text + "1"
End If
End SubPrivate Sub Command12_Click()
If Text1.Text = "" Then
Text1.Text = "2"
Else
Text1.Text = Text1.Text + "2"
End If
End SubPrivate Sub Command13_Click()
If Text1.Text = "" Then
Text1.Text = "3"
Else
Text1.Text = Text1.Text + "3"
End IfEnd SubPrivate Sub Command14_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "-"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command15_Click()
If Text1.Text = "" Then
MsgBox "ûÓÐÊý¾Ý¿ÉÇå³ý£¡", , "¾¯¸æ´°¿Ú"
Exit Sub
Else
Text1.Text = ""
End If
End SubPrivate Sub Command16_Click()
If Text1.Text = "" Then
Text1.Text = "0"
Else
Text1.Text = Text1.Text + "0"
End If
End SubPrivate Sub Command17_Click()
If InStr(Text1.Text, ".") = 0 Then
If Text1.Text = "" Then
Text1.Text = "."
Else
Text1.Text = Text1.Text + "."
End If
End If
End SubPrivate Sub Command18_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "+"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command19_Click()
If p = "jc" Then
fir = Val(Text1.Text)
Else
sec = Val(Text1.Text)
End If
If Text1.Text = "" And p <> "!" Then
MsgBox "Íü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
Else
Select Case p
Case "+"
Text1.Text = Str$(fir + sec)
Case "-"
Text1.Text = Str$(fir - sec)
Case "*"
Text1.Text = Str$(fir * sec)
Case "/"
If sec = 0 Then
MsgBox "Áã²»ÄÜ×ö³ýÊý£¡", 16, "¾¯¸æ´°¿Ú"
Exit Sub
End If
Text1.Text = Str$(fir / sec)
Case "%"
If sec = 0 Then
MsgBox "Áã²»ÄÜ×ö³ýÊý£¡", 16, "¾¯¸æ´°¿Ú"
Exit Sub
End If
If Int(fir) <> fir Or Int(sec) <> sec Then
MsgBox "Ö»ÓÐÕûÊý²ÅÄܽøÐÐÕû³ýÔËËã", 16, "¾¯¸æ´°¿Ú"
Exit Sub
Else
Text1.Text = Str$(fir \ sec)
End If
Case "cf"
Text1.Text = Str$(fir ^ sec)
Case "kf"
Text1.Text = Str$(fir ^ (1 / sec))
End Select
End If
End Sub
Private Sub Command20_Click()
yer = Year(Now)
mnth = Month(Now)
dy = Day(Now)
Select Case Weekday(Now)
Case 1
wkd$ = "ÈÕ"
Case 2
wkd$ = "Ò»"
Case 3
wkd$ = "¶þ"
Case 4
wkd$ = "Èý"
Case 5
wkd$ = "ËÄ"
Case 6
wkd$ = "Îå"
Case 7
wkd$ = "Áù"
End Select
Text1.Text = Str$(yer) + "Äê" + Str$(mnth) + "ÔÂ" + Str$(dy) + "ÈÕ ÐÇÆÚ" + wkd$
End SubPrivate Sub Command3_Click()
If Text1.Text = "" Then
Text1.Text = "9"
Else
Text1.Text = Text1.Text + "9"
End If
End Sub
Private Sub Command4_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "/"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command5_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "kf"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End If
End SubPrivate Sub Command6_Click()
If Text1.Text = "" Then
Text1.Text = "4"
Else
Text1.Text = Text1.Text + "4"
End IfEnd SubPrivate Sub Command7_Click()
If Text1.Text = "" Then
Text1.Text = "5"
Else
Text1.Text = Text1.Text + "5"
End IfEnd SubPrivate Sub Command8_Click()
If Text1.Text = "" Then
Text1.Text = "6"
Else
Text1.Text = Text1.Text + "6"
End IfEnd SubPrivate Sub Command9_Click()
If Text1.Text <> "" Then
fir = Val(Text1.Text)
Text1.Text = ""
p = "*"
Else
MsgBox "ÄúÍü¼ÇÊäÈëÊý¾ÝÁË£¡", 16, "¾¯¸æ´°¿Ú"
End IfEnd Sub
Private Sub Command2_Click()
If Text1.Text = "" Then
Text1.Text = "8"
Else
Text1.Text = Text1.Text + "8"
End IfEnd Sub
如果是數字鍵則判斷前一次是按的什么鍵。
如果前一次是運算符號或者enter鍵,則清除原來的數字顯示。
如果前一次按的是數字鍵,則本次的數字加在后面。
如果本次按的是運算符,則馬上計算出運算結果,并顯示出來。
最后還要記錄下本次的按鍵
偽代碼:
IF 本次按的是數字鍵 then
IF 上次按的是運算符 then
清除原來的數字顯示
else
數字加在后面
end
else if 本次按的是運算符 then
計算出運算結果,并顯示出來
else
非法的按鍵,發出beep,退出過程,不做其它反應
end if
最后還要記錄下本次的按鍵