Is it possible to use a timer to be able to count up, stop, and count down and be able to change the speed on the fly? Trying to make a simulator program that behaves like the real unit. The count also needs to stay in the 0000 format. ie; 0001, 0002, all the way up to 9999.

Thanks

Hello, you can do that. You need only to use the Timer tool. You need, for the count, to use a Variable that will save the number. Then you can change speed with TIMERNAME.Interval (in miliseconds) and use TIMERNAME.Stop, TIMERNAME.Start and use the event Tick of TIMERNAME that will do something when all the time since you started it will count, and when the milliseconds pass, it will do someting. Example: if I use 1000 ms (1 sec), when 1 sec passed, will do someting you want, but only in Tick event. I will code something for you, i will post it in a few minutes !

Edited 6 Years Ago by P0lT10n: n/a

easy stuff,, crate a timer,, and use random when you need to either speed up
or slow down to create a human like reaction.

if you want more, explain in detail what you need and ill give you some code

Well, can't go into too much detail as its military related. But Picture a box with 3 buttons and a dial switch. One button for moving a device one way and one to move in reverse and the third for stopping. The dial switch has 13 speeds, 1-13 controlling feet per minute. The 0000 from orginal post is in feet, which maxes out around 6000 but needs to be able to count that high and vary speeds up and down. Was gonna use a NumericUpDown control for the speed and a label displaying the speed in a quadruple zero format.

here is some code for the best timer i have,,

change the groupbox and labels to fit your software,, test it and see what it
does,, it is much like what you need,,you will have to del the hour,min,, and keep
the miliseconds and put it in the format that you want,, hence 0000


you will have to create 2 buttons, 1 to increace the timer and 1 to decreace,

the way you do this is set the timer interval,,

hence you can take the code below,, modify it and place it in a timer,,
after you place it in a timer,, you can then set the timer to either speed up
its interval or slow down its interval,, standard intervals are set to 1000
just set interval to 500 or 50 or 5000 or,, you get the picture,,

Timer1.Interval = "50"
etc,,

GroupBox11.Visible = True

        Try
            Label32.Text = "0"
            Label33.Text = "0"
            Label34.Text = "0"
            Label15.Text = "0"
            Label24.Text = "0"
            Label25.Text = "0"
            Label36.Text = "0"
            Label37.Text = "0"

            Label25.Text = DateTime.Now.Hour
            Label36.Text = DateTime.Now.Minute
            Label37.Text = DateTime.Now.Second

            Dim targetTime As DateTime = DateTime.Now.AddSeconds(DelayInSeconds)

            Label32.Text = DateTime.Now
            Do

                Application.DoEvents() ' keep app responsive
                System.Threading.Thread.Sleep(50) ' reduce CPU usage
                Label33.Text = (DateTime.Now)

                Label15.Text = (DateTime.Now.Minute)

                'hours
                Label23.Text = (DateTime.Now.Hour - Label25.Text)
                'minutes
                Label15.Text = (DateTime.Now.Minute - Label36.Text)
                'seconds
                Label24.Text = (DateTime.Now.Subtract(Label32.Text).ToString)


            Loop While DateTime.Now < targetTime
        Catch
        End Try
        Label32.Text = "0"
        Label33.Text = "0"
        Label34.Text = "0"
        Label15.Text = "0"
        Label24.Text = "0"
        Label25.Text = "0"
        Label36.Text = "0"
        Label37.Text = "0"

        GroupBox11.Visible = False
       
        Label53.Visible = False

ow,, calling that timer above would be calling it like this after
you place it in a function as so

Private Sub Delay(ByVal DelayInSeconds As Integer)
end function

then call it like this,, for 5 seconds or in your case 6 or 60 or 6000

delay(5)

received your file, opened it,,

i see a timer and it looks like it does what you want,

now ,, with the file i have,, describe in detail agian what you would like to see it do?

add a type of button that when pressed and held down will slow it down?
jeep slowing it down until you release the button? sort of a controll switch like
a radio receiver button type thing?

if not explain in detail for me k,,

Mike

Just need to have one button when pressed to make the number count in a positive direction. One button to stop counting, and one button to reverse the counting to go back to zero and into the negatives. A control, like the numericupdown, to select speeds. There will be 13 speeds. like for example, the real unit will operate at 10ft per minute at the number 1 setting. number 2 will go to 20ft per sec, roughly and so forth until 13 is reached. Just makes the counting speed up or down whether its counting positive or negative. If there are any former Sonar Technicans that were in the Navy, please let me know and I can explain further.

Prerequisites: 1 Timer, 2 Buttons, 1 NumericUpDown.

Public Class Form1

    Private myCount As String = "positive count"
    Private intCounter As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Text = "Start" : Button2.Text = "Positive"
        Me.Text = "0"
        NumericUpDown1.Minimum = 1
        NumericUpDown1.Maximum = 13
        Timer1.Interval = 50
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "Start" Then
            Button1.Text = "Stop" : Timer1.Start()
        Else
            Button1.Text = "Start" : Timer1.Stop()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button2.Text = "Positive" Then
            Button2.Text = "Negative" : myCount = "negative count"
        Else
            Button2.Text = "Positive" : myCount = "positive count"
        End If
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If myCount = "positive count" Then intCounter += 1
        If myCount = "negative count" Then intCounter -= 1
        Me.Text = intCounter & " - Interval Speed: " & Timer1.Interval
    End Sub

    Private Sub NumericUpDown1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
        Timer1.Interval = NumericUpDown1.Value * 100 / 2 '// just a random equation for project testing.

        '// or you can use a select case.

        'Select Case NumericUpDown1.Value
        '    Case 1
        '        Timer1.Interval = 50
        '    Case 2
        '        Timer1.Interval = 100
        '    Case 3
        '        Timer1.Interval = 150
        '        '// etc.
        'End Select

    End Sub
End Class

Codeorder, outstanding. Hit the nail right on the head. Thanks for help everyone. Much obliged.

... The count also needs to stay in the 0000 format. ie; 0001, 0002, all the way up to 9999....

I must have missed this part.:'(

Replace the last code line in Timer1_Tick() from:

Me.Text = intCounter & " - Interval Speed: " & Timer1.Interval

To:

Me.Text = intCounter.ToString("#000#") & " // Interval Speed: " & Timer1.Interval

:)

This question has already been answered. Start a new discussion instead.