Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 11
Reputation: tol is an unknown quantity at this point 
Solved Threads: 0
tol's Avatar
tol tol is offline Offline
Newbie Poster

Hi

 
0
  #1
Dec 1st, 2008
Thank God i found this site.
my first day in VB and i was given an assignment to simulate how a lift runs in VB with 4 floors. pls can any one help me so fa i have been able to design the interface. please i need help in writing the code...please a response will be HIGHLY appreciated. im good in oracle database but im firnding VB quite challenging. pls help deadline is fast approaching
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Hi

 
0
  #2
Dec 2nd, 2008
Here are the things to consider:
- what does an elevator do?
- how do you represent 4 floors in VB (a clue: you need a data structure)
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Hi

 
0
  #3
Dec 2nd, 2008
Welcome to DANIWEB tol...

Can you post your code here, then we'll give you back-up!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 11
Reputation: tol is an unknown quantity at this point 
Solved Threads: 0
tol's Avatar
tol tol is offline Offline
Newbie Poster

Re: Hi

 
0
  #4
Dec 4th, 2008
hi all, this is a copy of my code.
Though it still has some problems as sometimes its still hanging as some floors still has some problems. and my tutor was talking about using a boolean variable to relate it to the floors i.e buttons G,1,2,3 buts i dont really get what he means thats why i came to daniweb. please can anyone help me to make my even code better and time is of the essence. sometimes i wished I just stayed with Database Administration as i am good in DB programming.
I am determined to learn.

Public Class Form1
Dim floor, liftposition As Integer

Private Sub tmropen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmropen.Tick
pnllift.Width = pnllift.Width - 1
If pnllift.Width = 0 Then
tmropen.Stop()
End If

End Sub

Private Sub tmrup_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrup.Tick

Select Case floor
Case 0
If pnllift.Width = 79 Then
pnllift.Top = pnllift.Top - 1
If pnllift.Top = pnlgroundfloor.Top Then
tmrup.Stop()
tmropen.Start()
liftposition = 0
End If
End If
Case 1
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top - 1
If pnllift.Top = pnlfloor1.Top Then
tmrup.Stop()
tmropen.Start()
liftposition = 1
End If
End If
Case 2
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top - 1
If pnllift.Top = pnlfloor2.Top Then
tmrup.Stop()
tmropen.Start()
liftposition = 2
End If
End If
Case 3
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top - 1
If pnllift.Top = pnlfloor3.Top Then
tmrup.Stop()
tmropen.Start()
liftposition = 3
End If
End If

End Select

End Sub

Private Sub btn2up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2up.Click
'Up floor 1 button
floor = 1
btn2up.BackColor = Color.Black
tmrup.Start()
If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If

End Sub

Private Sub btn1up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1up.Click
'Up floor 1 button
floor = 0
btn1up.BackColor = Color.Black
If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If

End Sub

Private Sub btn2down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2down.Click
floor = 1
btn2down.BackColor = Color.Black
If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If

End Sub

Private Sub btn3up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3up.Click
floor = 2
btn3up.BackColor = Color.Black

If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If

End Sub

Private Sub btn4down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4down.Click
floor = 3
btn4down.BackColor = Color.Black

If liftposition > floor Then
if pnllift.Width <>79 then tmrclose.Start
tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If

End Sub

Private Sub tmrclose_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrclose.Tick
pnllift.Width = pnllift.Width + 1
If pnllift.Width = 79 Then
tmrclose.Stop()
End If
End Sub

Private Sub tmrdown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrdown.Tick
Select Case floor
Case 0
If pnllift.Width = 79 Then
pnllift.Top = pnllift.Top + 1
If pnllift.Top = pnlgroundfloor.Top Then
tmrdown.Stop()
tmropen.Start()
liftposition = 0
End If
End If
Case 1
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top + 1
If pnllift.Top = pnlfloor1.Top Then
tmrdown.Stop()
tmropen.Start()
liftposition = 1
End If
End If
Case 2
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top + 1
If pnllift.Top = pnlfloor2.Top Then
tmrdown.Stop()
tmropen.Start()
liftposition = 2
End If
End If
Case 3
If pnllift.Width = 79 Then

pnllift.Top = pnllift.Top + 1
If pnllift.Top = pnlfloor3.Top Then
tmrdown.Stop()
tmropen.Start()
liftposition = 3
End If
End If

End Select

End Sub

Private Sub btn3down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3down.Click
floor = 2
btn3down.BackColor = Color.Black

If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()
tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''pnllift.Height = 15
''pnllift.Width = 15
''pnlgroundfloor.t()



End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfloor1.Click
floor = 1
btn2down.BackColor = Color.Black
If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If
End Sub


Private Sub btnGroundfloor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGroundfloor.Click
'Up floor 1 button
floor = 0
btn1up.BackColor = Color.Black
If liftposition > floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrdown.Start()
ElseIf liftposition < floor Then
If pnllift.Width <> 79 Then tmrclose.Start()

tmrup.Start()
Else
tmropen.Start()

End If
End Sub
End Class
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Hi

 
0
  #5
Dec 4th, 2008
First, this is the VB 4/5/6 forum. You're coding with VB.NET which is a different forum in DaniWeb.

There's not a single, right solution. Here's one solution without any fancy UI, this more about the "logic" of an elevator.

First, you have 4 floors and an elevator can be only at the one floor at the time. Second, elevator can either move up or down (or stay in the same floor). So use a boolean array to represent floors and the elevator. Then you need methods to move elevator (up or down).
  1. Public Class Form1
  2.  
  3. ' Here's your floors and elevator
  4. Private ElevatorAtFloor(3) As Boolean
  5.  
  6. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7. ' Initialize our elevator to G floor
  8. ElevatorAtFloor(0) = True
  9. ElevatorAtFloor(1) = False
  10. ElevatorAtFloor(2) = False
  11. ElevatorAtFloor(3) = False
  12. End Sub
  13.  
  14. Private Sub MoveUp(ByVal NumberOfFloors As Integer)
  15. ' If this is not the top floor, move elevator up
  16. Dim i As Integer
  17.  
  18. ' First locate where the elevator is
  19. For i = 0 To ElevatorAtFloor.GetUpperBound(0)
  20. If ElevatorAtFloor(i) Then
  21. ' Elevator is at the floor i, can we move up NumberOfFloors
  22. If i + NumberOfFloors <= ElevatorAtFloor.GetUpperBound(0) Then
  23. ' Yes we can
  24. ElevatorAtFloor(i) = False
  25. ElevatorAtFloor(i + NumberOfFloors) = True
  26. Else
  27. ' No. Move to top floor
  28. ElevatorAtFloor(i) = False
  29. ElevatorAtFloor(ElevatorAtFloor.GetUpperBound(0)) = True
  30. End If
  31. Exit Sub ' We moved up and now exit sub
  32. End If
  33. Next i
  34.  
  35. End Sub
  36.  
  37. Private Sub MoveDown(ByVal NumberOfFloors As Integer)
  38. ' If this is not the G floor, move elevator down
  39. Dim i As Integer
  40.  
  41. ' First locate where the elevator is
  42. For i = 0 To ElevatorAtFloor.GetUpperBound(0)
  43. If ElevatorAtFloor(i) Then
  44. ' Elevator is at the floor i, can we move down NumberOfFloors
  45. If i - NumberOfFloors >= 0 Then
  46. ' Yes we can
  47. ElevatorAtFloor(i) = False
  48. ElevatorAtFloor(i - NumberOfFloors) = True
  49. Else
  50. ' No. Move to G floor
  51. ElevatorAtFloor(i) = False
  52. ElevatorAtFloor(0) = True
  53. End If
  54. Exit Sub ' We moved down and now exit sub
  55. End If
  56. Next i
  57.  
  58. End Sub
  59.  
  60. Private Sub MoveToFloor(ByVal ThisFloor As Integer)
  61. ' Move the elevator at the floor number ThisFloor
  62. Dim i As Integer
  63.  
  64. ' Check that ThisFloor is a valid value
  65. If ThisFloor < 0 OrElse ThisFloor > ElevatorAtFloor.GetUpperBound(0) Then
  66. ' Not a valid floor. Exit
  67. Exit Sub
  68. End If
  69.  
  70. ' First locate where the elevator is
  71. For i = 0 To ElevatorAtFloor.GetUpperBound(0)
  72. If ElevatorAtFloor(i) Then
  73. ' Now we know where the elevator is
  74. ' Determine if this is the right floor or do we have to move elavator up or down
  75. If i < ThisFloor Then
  76. ' Move elevator up
  77. MoveUp(ThisFloor - i) ' ThisFloor - i is the number of the floors we need to move up
  78. ElseIf i > ThisFloor Then
  79. ' Move elevator down
  80. MoveDown(i - ThisFloor) ' i - ThisFloor is the number of the floors we need to move down
  81. 'Else
  82. ' ' This is the right floor: i = ThisFloor
  83. End If
  84. Exit Sub ' We moved the elevator to ThisFloor and now exit sub
  85. End If
  86. Next i
  87.  
  88. End Sub
  89.  
  90. Private Sub ShowFloor()
  91. ' Show the floor number (G, 1-3) in a Label control
  92. Dim i As Integer
  93.  
  94. ' First locate where the elevator is
  95. For i = 0 To ElevatorAtFloor.GetUpperBound(0)
  96. If ElevatorAtFloor(i) Then
  97. If i = 0 Then
  98. Label1.Text = "G"
  99. Else
  100. Label1.Text = i.ToString
  101. End If
  102. End If
  103. Next i
  104.  
  105. End Sub
  106.  
  107. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  108. ' Get the floor number from the TextBox1
  109. Select Case TextBox1.Text.ToUpper
  110. Case "G"
  111. MoveToFloor(0)
  112. Case "1"
  113. MoveToFloor(1)
  114. Case "2"
  115. MoveToFloor(2)
  116. Case "3"
  117. MoveToFloor(3)
  118. End Select
  119. ShowFloor()
  120.  
  121. End Sub
  122.  
  123. End Class
Like I said, this not the only solution but has the basic "logic" and its implementation. That's what your prof/teacher is looking for. You may be a bit carried away with fancy UI instead of concentrating in the problem solution in itself in you code. But we are all learning all the time
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC