1、基本功能的设计
本例的计算器具有如下功能。
①科学计算器中,BackSpance、CE、C和运算符号+、-、*、/、.、-/+、=以及标准型计算器的设计。
②科学型角度弧度的设计。
③科学计算器中,x^2,x^3,x^y,1/x,n!,Log,In按键,及各进制转之间的相互转换的设计。
④科学计算器中,sin,cos,tan,dms,F-E,Exp、pi、Dat、s、Sum等按钮以sin/cos/tan计算时角度和弧度的转换的设计。
⑤科学行计算器中,Mod,Not,And,Xor,Int,Or,lsh,exit按钮。
⑥标准型菜单部分(查看菜单标准型、科学型。帮助菜单中包含关于(about)及标准型和科学型的数字
键和科学型的各进制转换的设计。
2、编成流程
3、详细设计
(1)Animal1窗体
Animal1窗体是标准的计算器操作界面。
Dim dflag As Integer
Dim i As Integer
Dim opnre As Integer
Dim prev As Double
Dim oflag As Integer
Dim ind As Integer
Private Sub Command1_Click(Index As Integer)
If ind = 4 Then
prev = 0
Text1.Caption = " "
ind = 0
End If
opnre = 0
If oflag = 0 Then
Text1.Caption = " "
End If
oflag = 1
If Command1(Index).Caption <> "." Then
If Text1.Caption <> " 0" Then
Text1.Caption = Text1.Caption & Command1(Index).Caption Else
Text1.Caption = " " & Command1(Index).Caption
End If
Else
If dflag = 0 Then
Text1.Caption = Text1.Caption & "."
dflag = 1
Else
MsgBox ("ILLEGAL SAIRAM")
End If
End If
End Sub
Private Sub Command2_Click(Index As Integer)
If opnre = 0 Or Index = 4 Then
If ind = 0 Then
prev = prev + Val(Text1.Caption)
ElseIf ind = 1 Then
prev = prev - Val(Text1.Caption)
ElseIf ind = 2 Then
If Val(Text1.Caption) = 0 Then
MsgBox ("SORRY DIVIDE ZERO")
Exit Sub
Else
prev = prev / Val(Text1.Caption)
End If
ElseIf ind = 3 Then
prev = prev * Val(Text1.Caption)
End If
Text1.Caption = Str(prev)
oflag = 0
End If
opnre = 1
ind = Index
dflag = 0
End Sub
Private Sub Command3_Click()
Text1.Caption = " 0"
End Sub
Private Sub Command4_Click()
dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
Text1.Caption = " 0"
End Sub
Private Sub Command5_Click()
Unload Me
scientific.Show
End Sub
Private Sub ecopy_Click()
Clipboard.Clear
Clipboard.SetText Text1.Caption
End Sub
Private Sub ecut_Click()
Clipboard.Clear
Clipboard.SetText Text1.Caption
Text1.Caption = ""
End Sub
Private Sub eexit_Click()
Unload Me
End Sub
Private Sub epaste_Click()
Text1.Caption = ""
Text1.Caption = Clipboard.GetText() End Sub
Private Sub eselectall_Click()
Clipboard.Clear
Clipboard.SetText Text1.Caption
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = Asc(".") Then
i = 10
Command1_Click (i)
Beep
ElseIf KeyAscii = Asc("0") Then
科学计算器使用i = 0
Command1_Click (i)
Beep
ElseIf KeyAscii = Asc("1") Then
i = 1
Command1_Click (i)
Beep
ElseIf KeyAscii = Asc("2") Then
i = 2
Command1_Click (i)
Beep
ElseIf KeyAscii = Asc("3") Then
i = 3
Command1_Click (i)
Beep
ElseIf KeyAscii = Asc("4") Then
i = 4
Command1_Click (i)
发布评论