制作简单计算器的vb编程一个label 一个文本框 16个按扭分别是清空.123+ 456- 789* 0 计算 /
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 22:53:43
制作简单计算器的vb编程一个label 一个文本框 16个按扭分别是清空.123+ 456- 789* 0 计算 /
制作简单计算器的vb编程
一个label 一个文本框 16个按扭分别是清空.123+ 456- 789* 0 计算 /
制作简单计算器的vb编程一个label 一个文本框 16个按扭分别是清空.123+ 456- 789* 0 计算 /
这个计算器包括了你要的功能,并且增加了语音发音功能.一定满足你的需要.成品在 http://www.iz88.net/pro_download/jsq.rar 下载观看.
有问题请在留言薄http://www.iz88.net/book/index.asp中留言说明.
Dim dflag As Integer
Dim I As Integer
Dim opnre As Integer
Dim prev As Double
Dim oflag As Integer
Dim ind As Integer
Dim soundbz As Boolean
Dim ProgramPath As String
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, ByVal Cy As Long, ByVal wFlags As Long) As Long
Public Sub SetOnTop(ByVal IsOnTop As Integer)
Dim rtn As Long
If IsOnTop = 1 Then
'将窗口置于最上面
rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)
Else
rtn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)
End If
End Sub
Private Sub Check1_Click()
If Check1.Value = 1 Then
SetOnTop 1
Else
SetOnTop 0
End If
End Sub
Private Sub Command1_Click(Index As Integer)
text1 = Trim(text1)
If Len(text1) > 20 Then
Beep
Exit Sub
End If
soundbz = False
MMControl1.Command = "Close"
MMControl1.FileName = ProgramPath & "/shengyin/" & Index & ".wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
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
Text = Mid(text1, 1, 1)
If Text = "." Then
text1 = "0" & text1
End If
Else
text1.Caption = " " & Command1(Index).Caption
End If
Else
If dflag = 0 Then
text1.Caption = text1.Caption & "."
dflag = 1
Else
Command6.SetFocus
Exit Sub
End If
End If
Command6.SetFocus
End Sub
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command2_Click(Index As Integer)
soundbz = False
MMControl1.Command = "Close"
If Index = 0 Then MMControl1.FileName = ProgramPath & "/shengyin/加.wav"
If Index = 1 Then MMControl1.FileName = ProgramPath & "/shengyin/减.wav"
If Index = 3 Then MMControl1.FileName = ProgramPath & "/shengyin/乘.wav"
If Index = 2 Then MMControl1.FileName = ProgramPath & "/shengyin/除.wav"
If Index = 4 Then
MMControl1.FileName = ProgramPath & "/shengyin/等于.wav"
soundbz = True
End If
MMControl1.Command = "Open"
MMControl1.Command = "Play"
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
text1 = "错误"
Beep
Command6.SetFocus
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
Command6.SetFocus
If Index = 4 Then
If Option1.Value = True Then text1 = Trim(Round(text1, 2))
If Option2.Value = True Then text1 = Trim(Round(text1, 3))
If Option3.Value = True Then text1 = Trim(Round(text1, 4))
If Option4.Value = True Then text1 = Trim(text1)
If text1 0 Then
Text = Mid(text1, 1, 1)
If Text = "." Then
text1 = "0" & text1
End If
End If
ls = Len(text1)
If ls 0 Then
For I = 1 To ls
t = Mid(text1, I, 1)
DoEvents
Do While (MMControl1.Mode 525) And soundbz
DoEvents
Loop
MMControl1.Command = "Close"
If t "." Then
If t = "-" Then
MMControl1.FileName = ProgramPath & "/shengyin/负.wav"
Else
MMControl1.FileName = ProgramPath & "/shengyin/" & t & ".wav"
End If
Else
MMControl1.FileName = ProgramPath & "/shengyin/10.wav"
End If
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Next I
End If
End If
End Sub
Private Sub Command2_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command3_Click()
soundbz = False
MMControl1.Command = "Close"
MMControl1.FileName = ProgramPath & "/shengyin/归零.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
text1.Caption = " 0"
Command6.SetFocus
End Sub
Private Sub Command3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command4_Click()
soundbz = False
MMControl1.Command = "Close"
MMControl1.FileName = ProgramPath & "/shengyin/清除.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
text1.Caption = " 0"
Command6.SetFocus
End Sub
Private Sub Command4_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command5_Click()
soundbz = False
SaveSetting App.EXEName, "保留", "n1", Option1.Value
SaveSetting App.EXEName, "保留", "n2", Option2.Value
SaveSetting App.EXEName, "保留", "n3", Option3.Value
SaveSetting App.EXEName, "保留", "n4", Option4.Value
SaveSetting App.EXEName, "置顶", "yorn", Check1.Value
' MMControl1.Command = "Close"
Unload Me
End Sub
Private Sub Command5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0
End Sub
Private Sub Command6_Click()
Command2_Click (4)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If text1 = "错误" Then
Command4_Click
End If
If KeyAscii = Asc(".") Then
I = 10
Command1_Click (I)
ElseIf KeyAscii = Asc("0") Then
I = 0
Command1_Click (I)
ElseIf KeyAscii = Asc("1") Then
I = 1
Command1_Click (I)
ElseIf KeyAscii = Asc("2") Then
I = 2
Command1_Click (I)
ElseIf KeyAscii = Asc("3") Then
I = 3
Command1_Click (I)
ElseIf KeyAscii = Asc("4") Then
I = 4
Command1_Click (I)
ElseIf KeyAscii = Asc("5") Then
I = 5
Command1_Click (I)
ElseIf KeyAscii = Asc("6") Then
I = 6
Command1_Click (I)
ElseIf KeyAscii = Asc("7") Then
I = 7
Command1_Click (I)
ElseIf KeyAscii = Asc("8") Then
I = 8
Command1_Click (I)
ElseIf KeyAscii = Asc("9") Then
I = 9
Command1_Click (I)
ElseIf KeyAscii = Asc("0") Then
I = 0
Command1_Click (I)
ElseIf KeyAscii = Asc("+") Then
I = 0
Command2_Click (I)
ElseIf KeyAscii = Asc("+") Then
I = 0
Command2_Click (I)
ElseIf KeyAscii = Asc("-") Then
I = 1
Command2_Click (I)
ElseIf KeyAscii = Asc("/") Then
I = 2
Command2_Click (I)
ElseIf KeyAscii = Asc("*") Then
I = 3
Command2_Click (I)
ElseIf KeyAscii = Asc("=") Or KeyAscii = 13 Then
I = 4
Command2_Click (I)
ElseIf KeyAscii = Asc("c") Or KeyAscii = Asc("C") Or KeyAscii = 27 Then
Command4_Click
ElseIf KeyAscii = Asc("d") Or KeyAscii = Asc("D") Then
Command3_Click
End If
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then
Unload Me
MsgBox "程序已运行,不能重复运行", 64, "系统提示"
End
End If
soundbz = True
dflag = 0
prev = 0
oflag = 0
ind = 0
opnre = 0
Clipboard.Clear
MMControl1.DeviceType = "WaveAudio"
ProgramPath = App.Path
Option1.Value = GetSetting(App.EXEName, "保留", "n1", True)
Option2.Value = GetSetting(App.EXEName, "保留", "n2", False)
Option3.Value = GetSetting(App.EXEName, "保留", "n3", False)
Option4.Value = GetSetting(App.EXEName, "保留", "n4", False)
Check1.Value = GetSetting(App.EXEName, "置顶", "yorn", 0)
If App.EXEName "jsq" Then MsgBox "语音计算器即将启动", vbOKOnly, "语音计算器"
End Sub
Private Sub Form_Unload(Cancel As Integer)
MMControl1.Command = "Close"
End
End Sub