小弟自学VB 5天,单独做的第一个小计算器忘各位高手指导
各位看看我自己 学了5天VB 做的,虽然 我会的函数不多,但我琢磨了一晚上 利用现学的做了个小计算器 ,可能有好多不足 ,好多 程序里的废话 ,高手看看给予指导
谢谢, 小弟QQ 12168088 希望 各位哥哥指导交流
这是我的代码,花了两个多小时.
[CODE]Dim number_add As Single
Dim number_multiplication As Single
Dim number_division As Single
Dim number_subtraction As Single
Dim a As Double
Private Function equal_to()
If number_add Then
add
ElseIf number_multiplication Then
multiplication
ElseIf number_division Then
division
ElseIf number_subtraction Then
subtraction
End If
End Function
Private Function add()
Text1.Text = a + Text1.Text
End Function
Private Function multiplication()
Text1.Text = a * Text1.Text
End Function
Private Function division()
Text1.Text = a / Text1.Text
End Function
Private Function subtraction()
Text1.Text = a - Text1.Text
End Function
Private Sub command_add_Click()
a = Val(Text1.Text)
Text1.Text = ""
number_multiplication = 0
number_division = 0
number_subtraction = 0
number_add = 1
End Sub
Private Sub command_division_Click()
a = Val(Text1.Text)
Text1.Text = ""
number_multiplication = 0
number_division = 1
number_subtraction = 0
number_add = 0
End Sub
Private Sub command_multiplication_Click()
a = Val(Text1.Text)
Text1.Text = ""
number_multiplication = 1
number_division = 0
number_subtraction = 0
number_add = 0
End Sub
Private Sub command_subtraction_Click()
a = Val(Text1.Text)
Text1.Text = ""
number_multiplication = 0
number_division = 0
number_subtraction = 1
number_add = 0
End Sub
Private Sub Command1_Click(Index As Integer)
If Val(Text1.Text) <= 0 Then
Text1.Text = Index
Else
Text1.Text = Text1.Text & Index
End If
End Sub
Private Sub division_Click()
b = division
End Sub
Private Sub command_equal_to_Click()
equal_to
End Sub
Private Sub Form_Load()
Text1.Text = 0
End Sub
Private Sub off_Click()
a = 0
Text1.Text = ""
End Sub
Private Sub point_Click()
Text1.Text = Text1.Text & "."
End Sub
Private Sub zero_Click()
a = 0
Text1.Text = 0
End Sub
[/CODE]
[此贴子已经被作者于2006-11-13 10:57:25编辑过]