Смекни!
smekni.com

Программирование в Бейсике (стр. 4 из 4)

Me.Label14(i).Caption = arStayName(Mis, i)

Next i

For i = 0 To (AllBuses - 1)

Image1(i).Visible = False

Next i

If Boom = True Then Boom = False: First_Stay_of_Buses

For i = 0 To (arBusCount(Combo1.ListIndex) - 1)

If Mis <> 0 Then

a = i

For j = 0 To (Mis - 1)

i = i + arBusCount(j)

Next j

Me.Image1(i).Visible = True

i = a

GoTo 1

Else

Me.Image1(i).Visible = True

End If

1: Next i

Me.Timer1 = True

If Misk <> 999 Then If Image1(Misk).Visible = True Then Image1_Click (Misk)

t = Time

tnow = Val(Mid$(Str$(t), 1, 2))

If tnow > t0 And tnow < t1 Or tnow > t2 And tnow < t3 Or tnow > t4 And tnow < t5 Or _

tnow > t6 And tnow <= t7 Then Label8.Caption = "60 êì/÷": Timer1.Interval = 5

If tnow >= t1 And tnow <= t2 Or tnow >= t3 And tnow <= t4 Or tnow >= t5 And tnow <= t6 Then _

Label8.Caption = "30 êì/÷": Timer1.Interval = 10

If tnow = 24 Or tnow >= 0 And tnow <= 4 Then Label8.Caption = " - ": 'Timer1.Enabled = False

Label13.Caption = "100"

End Sub

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

For z = 0 To (Combo1.ListCount - 1)

Me.Picture1.PSet (arStayAbsciss(z, 0), arStayOrdinata(z, 0))

For i = 0 To (arStayCount(z) - 1)

Me.Picture1.Line -(arStayAbsciss(z, i), arStayOrdinata(z, i)), QBColor(z + 3)

Next i

For i = 0 To (arBusCount(z) - 1)

If z <> 0 Then

a = i

For j = 0 To (z - 1)

i = i + arBusCount(j)

Next j

Me.Image1(i).Visible = True

i = a

GoTo 1

Else

Me.Image1(i).Visible = True

End If

1: Next i

Next z

End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Combo1_Click

End Sub

Private Sub Command2_Click()

Misk = 999

Unload Me

End Sub

Private Sub Form_Load()

Misk = 999

Boom = True

MovePossible = False

If Len(Dir("c:&bsol; Курсовая моя&bsol;маршруты.txt")) = 0 Then

MsgBox " Файл маршрутов не найден!!!" + vbCrLf + _

" Проверьте его наличие: 'c:&bsol; Курсовая моя&bsol;маршруты.txt'"

Combo1.Enabled = False

Label11.Visible = False

Exit Sub

End If

Open "c:&bsol; Курсовая моя&bsol;маршруты.txt" For Input As 1

LinesCount = 0

Do While Not EOF(1)

Input #1, arLinesName(LinesCount)

Combo1.AddItem arLinesName(LinesCount)

LinesCount = LinesCount + 1

Loop

Close 1

AllBuses = 0

For Mis = 0 To (Combo1.ListCount - 1)

If Len(Dir("c:&bsol;Курсоваямоя&bsol;" + Combo1.List(Mis) + ".txt")) = 0 Then

MsgBox " Файл маршрутов не найден!!!" + vbCrLf + _

" Проверьте его наличие: 'c:&bsol;Курсовая&bsol;" + Combo1.List(Mis) + ".txt'"

Else

Work_With_Files

AllBuses = AllBuses + arBusCount(Mis)

End If

Next Mis

Fuel(0) = 100

For i = 1 To (AllBuses - 1)

Load Image1(i)

Fuel(i) = 100

Next i

For i = 1 To 35

Load Image2(i)

Load Label14(i)

Next i

End Sub

Public Static Sub Work_With_Files()

arBusCount(Mis) = 0

arStayCount(Mis) = 0

Open "c:&bsol;Курсоваямоя&bsol;" + Combo1.List(Mis) + ".txt" For Input As 2

Do While Not EOF(2)

Input #2, a$

Select Case a$

Case "автобус": Input #2, arBusNumber(Mis, arBusCount(Mis))

Case "водитель": Input #2, arDriveName(Mis, arBusCount(Mis))

Case "кондуктор": Input #2, arConductorName(Mis, arBusCount(Mis))

arBusCount(Mis) = arBusCount(Mis) + 1

Case "остановка": Input #2, arStayName(Mis, arStayCount(Mis))

Input #2, arStayAbsciss(Mis, arStayCount(Mis))

Input #2, arStayOrdinata(Mis, arStayCount(Mis))

arStayCount(Mis) = arStayCount(Mis) + 1

End Select

Loop

Close 2

End Sub

Private Sub Image1_Click(Index As Integer)

Misk = Index

For i = 0 To (AllBuses - 1)

Image1(i).Picture = LoadPicture("c:&bsol; Курсовая моя&bsol;Иконки &bsol;Blue Bus.ico")

Next i

For i = 0 To (arBusCount(Mis) - 1)

If Mis <> 0 Then

a = i

For j = 0 To (Mis - 1)

i = i + arBusCount(j)

Next j

If i = Index Then

Frame1.Visible = False

Label4.Caption = arBusNumber(Mis, a)

Text1.Text = arDriveName(zmis, a)

Text2.Text = arConductorName(Mis, a)

Me.Label13.Caption = Str$(Fuel(Index))

Me.Image1(i).Picture = LoadPicture("c:&bsol; Курсовая моя&bsol;Иконки &bsol;Purple Bus.ico")

End If

i = a

GoTo 1

Else

If i = Index Then

Frame1.Visible = False

Label4.Caption = arBusNumber(Mis, i)

Text1.Text = arDriveName(Mis, i)

Text2.Text = arConductorName(Mis, i)

Me.Label13.Caption = Str$(Fuel(Index))

Me.Image1(i).Picture = LoadPicture("c:&bsol; Курсовая моя&bsol;Иконки &bsol;Purple Bus.ico")

End If

End If

1: Next i

End Sub

Private Sub Image1_DragOver(Index As Integer, Source As Control, X As Single, Y As Single, State As Integer)

Pisk = Index

End Sub

Private Sub Image2_Click(Index As Integer)

If Misk <> 999 Then

If Image1(Misk).Visible = True Then

x0(Mis, Misk) = Val(arStayAbsciss(Mis, Index))

y0(Mis, Misk) = Val(arStayOrdinata(Mis, Index))

If x0(Mis, Misk) = Val(arStayAbsciss(Mis, Index)) _

Then arStayPast(Mis, Misk) = Index

If arStayPast(Mis, Misk) = (arStayCount(Mis) - 1) Then arStayEdit(Mis, Misk) = -1

If arStayPast(Mis, Misk) = 0 Then arStayEdit(Mis, Misk) = 1

End If

End If

End Sub

Private Sub Image3_Click()

If Misk <> 999 Then If Image1(Misk).Visible = True Then Fuel(Misk) = 100

End Sub

Private Sub mnuEditNext_Click()

If Misk <> 999 Then

If Image1(Misk).Visible = True Then

x0(Mis, Misk) = Val(arStayAbsciss(Mis, arStayPast(Mis, Misk) + arStayEdit(Mis, Misk)))

If x0(Mis, Misk) = Val(arStayAbsciss(Mis, arStayPast(Mis, Misk) + arStayEdit(Mis, Misk))) _

Then arStayPast(Mis, Misk) = arStayPast(Mis, Misk) + arStayEdit(Mis, Misk)

End If

End If

End Sub

Private Sub mnuEditPast_Click()

If Misk <> 999 Then

If Image1(Misk).Visible = True Then

x0(Mis, Misk) = Val(arStayAbsciss(Mis, arStayPast(Mis, Misk)))

End If

End If

End Sub

Private Sub mnuMove_Click()

If MovePossible = True Then

Me.mnuMove.Caption = "Включить режим: передвижение автобусов"

For i = 0 To (AllBuses - 1)

Image1(i).DragMode = 0

Next i

MovePossible = False

Exit Sub

End If

If MovePossible = False Then

Me.mnuMove.Caption = "Включить: режим выбора автобуса"

MovePossible = True

For i = 0 To (AllBuses - 1)

Image1(i).DragMode = 1

Next i

End If

End Sub

Private Sub Picture1_DragDrop(Source As Control, X As Single, Y As Single)

If Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk))) > Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk) + arStayEdit(Mis, Pisk))) _

Then

For i = Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk))) To Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk) + arStayEdit(Mis, Pisk))) Step -1

If i = Fix(X) Then x0(Mis, Pisk) = X

Next i

Else

For i = Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk))) To Val(arStayAbsciss(Mis, arStayPast(Mis, Pisk) + arStayEdit(Mis, Pisk))) Step 1

If i = Fix(X) Then x0(Mis, Pisk) = X

Next i

End If

End Sub

Private Sub Timer1_Timer()

For i = 0 To (AllBuses - 1)

Fuel(i) = Fuel(i) - 1 / (1000 * Me.Timer1.Interval)

If i = Misk Then Me.Label13.Caption = Str$(Fuel(Misk))

If Fuel(i) = 0 Then Fuel(i) = 100

Next i

For z = 0 To (Combo1.ListCount - 1)

For i = 0 To (arBusCount(z) - 1)

If z <> 0 Then

a = i

For j = 0 To (z - 1)

i = i + arBusCount(j)

Next j

End If

If arStayPast(z, i) = (arStayCount(z) - 1) Then arStayEdit(z, i) = -1

If arStayPast(z, i) = 0 Then arStayEdit(z, i) = 1

If Val(arStayAbsciss(z, arStayPast(z, i))) > Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))) _

Then arCoordEdit(z, i) = -1

If Val(arStayAbsciss(z, arStayPast(z, i))) < Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))) _

Then arCoordEdit(z, i) = 1

If Val(arStayAbsciss(z, arStayPast(z, i))) = Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))) _

Then arCoordEdit(z, i) = 0

k(z, i) = (Val(arStayOrdinata(z, arStayPast(z, i))) - Val(arStayOrdinata(z, arStayPast(z, i) + arStayEdit(z, i)))) / _

(Val(arStayAbsciss(z, arStayPast(z, i))) - Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))))

b(z, i) = Val(arStayOrdinata(z, arStayPast(z, i))) - k(z, i) * Val(arStayAbsciss(z, arStayPast(z, i)))

Dim c As Single

c = Cos(Atn(k(z, i)))

x0(z, i) = x0(z, i) + c * 2 * arCoordEdit(z, i)

y0(z, i) = k(z, i) * x0(z, i) + b(z, i)

Image1(i).Move x0(z, i) - Image1(i).Width / 2, y0(z, i) - Me.Image1(i).Height / 2

If arCoordEdit(z, i) = 1 Then

If x0(z, i) >= Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))) _

Then arStayPast(z, i) = arStayPast(z, i) + arStayEdit(z, i)

End If

If arCoordEdit(z, i) = -1 Then

If x0(z, i) <= Val(arStayAbsciss(z, arStayPast(z, i) + arStayEdit(z, i))) _

Then arStayPast(z, i) = arStayPast(z, i) + arStayEdit(z, i)

End If

If z <> 0 Then i = a

Next i

Next z

End Sub

Public Static Sub First_Stay_of_Buses()

For z = 0 To (Combo1.ListCount - 1)

For i = 0 To (arBusCount(z) - 1)

a = i

If z <> 0 Then

a = i

For j = 0 To (z - 1)

i = i + arBusCount(j)

Next j

End If

If a = 0 Then

arStayEdit(z, i) = 1

arStayPast(z, i) = 0

Me.Image1(i).Move arStayAbsciss(z, 0) - Image1(i).Width / 2, _

arStayOrdinata(z, 0) - Image1(i).Height / 2

x0(z, i) = Val(arStayAbsciss(z, 0)): y0(z, i) = Val(arStayOrdinata(z, 0))

'MsgBox Str$(z) + " - " + Str$(i) + " - " + Str$(X0(z, i)) + " " + Str$(Y0(z, i))

Else

arStayEdit(z, i) = 1

arStayPast(z, i) = arStayPast(z, i - 1) + 1

Me.Image1(i).Move arStayAbsciss(z, arStayPast(z, i)) _

- Image1(i).Width / 2, _

arStayOrdinata(z, arStayPast(z, i)) _

- Image1(i).Height / 2

x0(z, i) = Val(arStayAbsciss(z, arStayPast(z, i)))

y0(z, i) = Val(arStayOrdinata(z, arStayPast(z, i)))

'MsgBox Str$(z) + " - " + Str$(i) + " - " + Str$(X0(z, i)) + " " + Str$(Y0(z, i))

End If

i = a

1: Next i

Next z

End Sub