Hi everyone, well I have trying to do an elevator simulator, wich have to includo the panel with the floor, available floors, and a button panel with available floors and button up, down, but I dont understand is how to use the timers for up and down, because I vague idea to select the floors is to usea a for or select case but I dont know wich one is the most appropiate in this case. Wha tI have so far is:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer2.Enabled = False
        If lbl1.Text = "4" Then
            lbl1.Text = "1"
        Else
            lbl1.Text = Val(lbl1.Text) + 1
        End If
        Button1_Click("", e)
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Timer1.Enabled = True
        If lbl1.Text = "4" Then
            lbl1.Text = "1"
        Else
            lbl1.Text = Val(lbl1.Text) - 1
        End If
        Button2_Click("", e)
    End Sub

    Private Sub nvl1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nvl1.CheckedChanged
        If nvl1.Checked = True Then
            shp1.BackColor = Color.Red
            lbl1_nvl1.ForeColor = Color.Red
        Else
            shp1.BackColor = Color.Green
            lbl1_nvl1.ForeColor = Color.Green
            shp2.BackColor = Color.Red
            lbl2_nvl2.ForeColor = Color.Red
            shp3.BackColor = Color.Red
            lbl3_nvl3.ForeColor = Color.Red
        End If
    End Sub

    Private Sub nvl2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nvl2.CheckedChanged
        If nvl2.Checked = True Then
            shp2.BackColor = Color.Red
            lbl2_nvl2.ForeColor = Color.Red
        Else
            shp2.BackColor = Color.Green
            lbl2_nvl2.ForeColor = Color.Green
            shp1.BackColor = Color.Red
            lbl1_nvl1.ForeColor = Color.Red
            shp3.BackColor = Color.Red
            lbl3_nvl3.ForeColor = Color.Red
        End If
    End Sub

    Private Sub nvl3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nvl3.CheckedChanged
        If nvl3.Checked = True Then
            shp3.BackColor = Color.Red
            lbl3_nvl3.ForeColor = Color.Red
        Else
            shp3.BackColor = Color.Green
            lbl3_nvl3.ForeColor = Color.Green
            shp1.BackColor = Color.Red
            lbl1_nvl1.ForeColor = Color.Red
            shp2.BackColor = Color.Red
            lbl2_nvl2.ForeColor = Color.Red
        End If
    End Sub
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If lbl1.Text = "1" Then
            nvl1.Checked = True
        ElseIf lbl1.Text = "2" Then
            nvl2.Checked = True
        ElseIf lbl1.Text = "3" Then
            nvl3.Checked = True
        ElseIf lbl1.Text = "4" Then
            nvl4.Checked = True
        End If
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        If lbl1.Text = "1" Then
            nvl1.Checked = True
        ElseIf lbl1.Text = "2" Then
            nvl2.Checked = True
        ElseIf lbl1.Text = "3" Then
            nvl3.Checked = True
        ElseIf lbl1.Text = "4" Then
            nvl4.Checked = True
        End If
    End Sub

This just shows the levels and the timer1 just go up and a little "screen" shows at what floors is the elevator but this just go up and start from one again.

Thanks in advance for the help.

You must enable only one timer at a time.
Timer1 to go up.
Timer2 to go down.

When any Timer reaches the destination floor, it shoud be self disabled.

On both timers you check for floor 4. IMO you should chek if the current floor is the destination or greater on timer1 and the destination or lower in timer2.

Hope this helps

What about having one timer for motion and the other for doors. Each tick of the first timer would advance the elevator one unit in whatever direction it happens to be moving (unless the elevator is currently stationary). It would be a state-driven device with states suca as "stationary", "moving", "doors open", etc. A second timer could run when the doors are open and would determine when the doors should close.

Well I think I understand a little but with the timers is that I have the problem because I was looking for examples and I found that in some cases the timer is in miliseconds and in other cases the timers are in steps like 1, 2, 3, 4, etc...

In order to clarify the 3 distinct timers in .NET you can read this article.

The most commonly used is the Sysytem.Windows.Forms.Timer and uses always miliseconds as the unit of measure.

For your pourpuse, I would recomment to use it.

Hope this helps

How about something like this:

Create 9 buttons named btn1 - btn9. Stack them vertically and space them so that they are 50 y units apart centre to centre. Create a label and place it to the right of btn1. Create a timer for the elevator car and give it an interval of 50. Create a second timer for the door and give it an interval of 1000. You can start the door timer when the door opens. After 5 seconds you can close the door. As for the car timer, when the elevator is moving, on every "tick" of the timer you can adjust the Y position of the label by one. This way, the label will move up and down to indicate the location of the car. On every "tick" you can check if the label lines up with a floor button. If the floor button has been clicked you can stop at that floor (disable car timer, open door, enable door timer).

Ok, here is where determines where the timer is moving, now it moves "up" cause add 1 to the "current" level. If I am correct here is where do I have to create a select case from 1 to 10 wich means the number of floor that I have in the "building" and I have created a button panel with 10 buttons with all the code I just marck the radio buttons as the count goes by one. I have attached a screen from the window I am using with all the code.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If lbl_nvl_a.Text = "4" Then
            lbl_nvl_a.Text = "1"
        Else
            lbl_nvl_a.Text = Val(lbl_nvl_a.Text) + 1
        End If
        btn_nvl1_Click("", e)
    End Sub
Attachments elevator.png 97.9 KB

Also, instead of having a separate checkbox and button for each floor you could get rid of the checkbox and just use the buttons. When a button is clicked you could change the background colour from grey to yellow, then change it back from yellow to grey when the car stops at that floor. You wouldn't need the select statement in the button handler. You could just modify the properties of the button specified by "sender".

This article has been dead for over six months. Start a new discussion instead.