VB作業之比較三個數的大小
阿新 • • 發佈:2019-02-20
下面是我編寫的程式程式碼:
Private Sub Command1_Click()
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim max As Integer
A = Val(Text1.Text)
B = Val(Text2.Text)
C = Val(Text3.Text)
If A > B Then
max = A
Else
max = B
End If
If C > max Then
max = C
End If
Print max
End Sub
接著編寫“清除”事件的程式:
Private Sub Command2_Click()
Me.Cls
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.Private Sub Command2_Click()
Me.Cls
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub 心得體會:這次作業相比上次作業只是增加了一個個數,但難度似乎增加的很大,摸索出這一類程式的規律,程式就很容易編寫了;同樣這次用到了“SetFocus”使程式更完美,用起來更方便