這是個模擬電梯動作的程式碼!!
這只是一部電梯而已
可是我要寫一個很多部的電梯同時在動作的程式
想了好幾了一直想不出個頭緒來..
倒底要怎樣寫一個副程式來完成多部電梯同時動作
麻煩各位前輩指導一下
謝謝!!
Dim counter As Integer
Dim sw As Integer
Dim sw_1 As Integer
Dim ii As Integer
Dim Clicker As Integer
Dim INDEX_1 As Integer
Dim INDEX_2 As Integer
Dim MOVE_ONE_TWO As Integer
Dim SW_ONE As Integer
Private Sub A1_Click(Index As Integer)
INDEX_CLS
INDEX_1 = 1
Timer2.Enabled = True
End Sub
Private Sub A2_Click(Index As Integer)
INDEX_CLS
INDEX_1 = 2
Timer2.Enabled = True
End Sub
Private Sub A3_Click(Index As Integer)
INDEX_CLS
INDEX_1 = 3
Timer2.Enabled = True
End Sub
Private Sub A4_Click(Index As Integer)
INDEX_CLS
INDEX_1 = 4
Timer2.Enabled = True
End Sub
Private Sub A5_Click(Index As Integer)
INDEX_CLS
INDEX_1 = 5
Timer2.Enabled = True
End Sub
Private Sub Command1_Click(Index As Integer)
Clicker = Index
End Sub
Private Sub Command2_Click(Index As Integer)
Clicker = Index
End Sub
Private Sub Form_Load()
Clicker = 0
ii = 0
sw = 0
counter = 0
INDEX_1 = 0
Label2.Caption = "電梯正在移動中......"
For i = 1 To 5
Shape1(i).FillColor = Me.BackColor
'Shape2(i).FillColor = Me.BackColor
Next i
End Sub
Private Sub Timer1_Timer()
If Clicker = 0 Then
MOVE_1
Else
If Clicker = counter Then Timer1.Enabled = False: index_cls_tow
If Clicker > counter Then
counter = counter + 1
showcolor
End If
If Clicker < counter Then
counter = counter - 1
showcolor
End If
End If
End Sub
Public Sub showcolor() '顯示出目前電梯停留在那個樓層
For i = 1 To 5
Shape1(i).FillColor = Me.BackColor
Next i
Shape1(counter).FillColor = RGB(255, 0, 0)
Label1(0).Caption = counter
End Sub
Public Sub INDEX_CLS()
A1(Clicker).Visible = False
A2(Clicker).Visible = False
A3(Clicker).Visible = False
A4(Clicker).Visible = False
A5(Clicker).Visible = False
End Sub
Public Sub INDEX_MOVE()
'Do
'counter
'Loop Until (INDEX_1 = counter)
End Sub
Public Sub MOVE_1() '電梯移動
If counter >= 5 Then sw = 1
If sw = 1 Then
counter = counter - 1
If counter <= 1 Then sw = 0
showcolor
Else
counter = counter + 1
showcolor
End If
Label1(0).Caption = counter
End Sub
Public Sub index_cls_tow()
A1(Clicker).Visible = True
A2(Clicker).Visible = True
A3(Clicker).Visible = True
A4(Clicker).Visible = True
A5(Clicker).Visible = True
End Sub
Private Sub Timer2_Timer()
If sw_1 = 1 Then
ii = ii + 1
If ii = 3 Then
sw_1 = 0
ii = 0
Clicker = 0
Label2.Caption = "電梯正在移動中......"
Timer1.Enabled = True
Timer2.Enabled = False
End If
Else
If counter > INDEX_1 Then
counter = counter - 1
showcolor
Label2.Caption = "電梯正在前往第 " & INDEX_1 & " 樓層中......"
End If
If counter < INDEX_1 Then
counter = counter + 1
showcolor
Label2.Caption = "電梯正在前往第 " & INDEX_1 & " 樓層中......"
End If
If counter = INDEX_1 Then
Label2.Caption = "電梯已經到達所在樓層!!"
sw_1 = 1
End If
End If
End Sub