一个text.加,减,乘,除,等于,清除6个按扭.
要求:1,直接从键盘输入数字,并判断如果输入的不是数字不做显示
2,在输入加减乘除运算符时,在文本筐中显示(在输入的数字下方)
3,点等于号时,也同样在文本中显示(和运算符的显示方式相同),并在下一行显示结果.
谢谢,希望能给出这个 程序的VB原码.
整了一个,还不算太成熟。不过楼主所说的主要功能都实现了,是不是能满足楼主的要求就不知道了。有什么问题欢迎楼主提出!
Dim I As Byte
Dim First As Single, Second As Single, Third As Single
Private Sub Command1_Click(Index As Integer)
If Label1.Caption = "" And Index <> 5 Then
First = Val(Text1.Text)
Text2.Text = Text1.Text
Text1.Text = ""
Else
Second = Val(Text1.Text) '42*43+44,45-46.47/
End If
Select Case Index
Case 0 '加法
Label1.Caption = "+"
Case 1 '减法
Label1.Caption = "-"
Case 2 '乘法
Label1.Caption = "*"
Case 3 '除法
Label1.Caption = "/"
Case 4 '清除
Text1.Text = ""
Case 5 '等于
If Label1.Caption <> "" Then
Select Case Asc(Label1.Caption)
Case 42
Third = First * Second
Case 43
Third = First + Second
Case 45
Third = First - Second
Case 47
If Second = 0 Then
MsgBox "请注意,除数不能为0"
Text1.Text = ""
Exit Sub
End If
Third = First / Second
End Select
Text2.Text = Third
Label1.Caption = ""
Text1.Text = ""
End If
End Select
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text1.Width = 4000
Text1.Height = 400
Text1.Left = 100
Text1.Top = 100
Text2.Text = ""
Text2.Width = 4000
Text2.Height = 400
Text2.Left = 100
Text2.Top = 500
Label1.Width = 400
Label1.Height = 400
Label1.Left = 100
Label1.Top = 900
Label1.Caption = ""
'Label1(1).Caption = "="
Command1(0).Caption = "加"
Command1(1).Caption = "减"
Command1(2).Caption = "乘"
Command1(3).Caption = "除"
Command1(4).Caption = "清除"
Command1(5).Caption = "等于"
For I = 0 To 5
Command1(I).Width = 800
Command1(I).Height = 400
Command1(I).Left = 400 + I * 1000
Command1(I).Top = 1400
Next
Text2.Locked = True
Command2.Caption = "退出"
Text1.Alignment = 1
Text2.Alignment = 1
Text1.FontSize = 12
Text2.FontSize = 12
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 45 '-
If Text1.Text <> "" Then KeyAscii = 0
Case 46 '.
If InStr(Text1.Text, ".") Then KeyAscii = 0
Case 48 To 57 '0-9
Case Else
KeyAscii = 0
End Select
End Sub
已经运行过了。
Dim I As Byte
Dim First As Single, Second As Single, Third As Single
Private Sub Command1_Click(Index As Integer)
If Label1.Caption = "" And Index <> 5 Then
First = Val(Text1.Text)
Text2.Text = Text1.Text
Text1.Text = ""
Else
Second = Val(Text1.Text) '42*43+44,45-46.47/
End If
Select Case Index
Case 0 '加法
Label1.Caption = "+"
Case 1 '减法
Label1.Caption = "-"
Case 2 '乘法
Label1.Caption = "*"
Case 3 '除法
Label1.Caption = "/"
Case 4 '清除
Text1.Text = ""
Case 5 '等于
If Label1.Caption <> "" Then
Select Case Asc(Label1.Caption)
Case 42
Third = First * Second
Case 43
Third = First + Second
Case 45
Third = First - Second
Case 47
If Second = 0 Then
MsgBox "请注意,除数不能为0"
Text1.Text = ""
Exit Sub
End If
Third = First / Second
End Select
Text2.Text = Third
Label1.Caption = ""
Text1.Text = ""
End If
End Select
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text1.Width = 4000
Text1.Height = 400
Text1.Left = 100
Text1.Top = 100
Text2.Text = ""
Text2.Width = 4000
Text2.Height = 400
Text2.Left = 100
Text2.Top = 500
Label1.Width = 400
Label1.Height = 400
Label1.Left = 100
Label1.Top = 900
Label1.Caption = ""
'Label1(1).Caption = "="
Command1(0).Caption = "加"
Command1(1).Caption = "减"
Command1(2).Caption = "乘"
Command1(3).Caption = "除"
Command1(4).Caption = "清除"
Command1(5).Caption = "等于"
For I = 0 To 5
Command1(I).Width = 800
Command1(I).Height = 400
Command1(I).Left = 400 + I * 1000
Command1(I).Top = 1400
Next
Text2.Locked = True
Command2.Caption = "退出"
Text1.Alignment = 1
Text2.Alignment = 1
Text1.FontSize = 12
Text2.FontSize = 12
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 45 '-
If Text1.Text <> "" Then KeyAscii = 0
Case 46 '.
If InStr(Text1.Text, ".") Then KeyAscii = 0
Case 48 To 57 '0-9
Case Else
KeyAscii = 0
End Select
End Sub
已经运行过了。
温馨提示:答案为网友推荐,仅供参考