none
Timers RRS feed

  • Question

  • I have set up a timer using the code below. At the number adjacent to the case my function 'ShuttleA' is called.

    'ShuttleA' function is a function that getskeystate, which inturn from the user interface tallies a response in a text box.

    My problem is that the program runs fine when calling the function at eg; at 10 seconds, case 10.

    But i want to be able to call the function eg; at 8 seconds to 11 seconds. Or create a tolerance of eg; 1 second either side of eg; 10.

    Any help would be apprieciate as I am new and confused. Thank you

    Private

     

    Sub Timer1_Tick(ByVal sender As System.Object,ByVal eAs System.EventArgs)Handles Timer1.Tick

     

    Dim

     

    seconds AsInteger

    seconds += 1

    Label1.Text = seconds

     

    SelectCase seconds

     

     

    Case 1

    Label2.Text = (

    "1.1")

     

    Case 10

    Label2.Text = (

    "1.2")

    ShuttleA()

     

    Case 20

    Label2.Text = (

    "1.3")

    ShuttleA()

     

    Case 30

    Label2.Text = (

    "1.4")

    ShuttleA()

     

    Case 40

    Label2.Text = (

    "1.5")

    ShuttleA()

     

    Case 50

    Label2.Text = (

    "1.6")

    ShuttleA()

     

    Case 60

    Label2.Text = (

    "1.7")

    ShuttleA()

     

    Case 70

    Label2.Text = (

    "2.1")

    ShuttleA()

     

    Case 80

    Label2.Text = (

    "2.2")

    ShuttleA()

     

    Case 90

    Label2.Text = (

    "2.3")

    ShuttleA()

     

    Case 100

    Label2.Text = (

    "2.4")

    ShuttleA()

     

    Case 110

    Label2.Text = (

    "2.5")

    ShuttleA()

     

    Case 120

    Label2.Text = (

    "2.6")

    ShuttleA()

     

    Case 130

    Label2.Text = (

    "2.7")

    ShuttleA()

     

    Case 140

    Label2.Text = (

    "2.8")

    ShuttleA()

     

    Case 150

    Label2.Text = (

    "3.1")

    ShuttleA()

     

    Case 160

    Label2.Text = (

    "2.2")

    ShuttleA()

     

    EndSelect

     

    EndSub

     

    Thursday, April 15, 2010 1:06 PM

Answers

  • You could use the case statement like shown below. I think the 'To' option must help you. Look at 

    http://msdn.microsoft.com/en-us/library/cy37t14y.aspx

     

    Dim someVal As Integer = 8
    Select Case someVal
    Case 1 To 4
    Debug.WriteLine("Between 1 and 4, inclusive")
    ' The following is the only Case clause that evaluates to True.
    Case 5, 6, 7
    Debug.WriteLine("Between 5 and 7, inclusive")
    Case 8 To 9
    Debug.WriteLine("Equal to 8 or 9")
    Case Else
    Debug.WriteLine("Not between 1 and 9, inclusive")
    End Select


     

    • Marked as answer by warn1936 Friday, April 16, 2010 7:40 AM
    Friday, April 16, 2010 12:39 AM

All replies

  • You could use the case statement like shown below. I think the 'To' option must help you. Look at 

    http://msdn.microsoft.com/en-us/library/cy37t14y.aspx

     

    Dim someVal As Integer = 8
    Select Case someVal
    Case 1 To 4
    Debug.WriteLine("Between 1 and 4, inclusive")
    ' The following is the only Case clause that evaluates to True.
    Case 5, 6, 7
    Debug.WriteLine("Between 5 and 7, inclusive")
    Case 8 To 9
    Debug.WriteLine("Equal to 8 or 9")
    Case Else
    Debug.WriteLine("Not between 1 and 9, inclusive")
    End Select


     

    • Marked as answer by warn1936 Friday, April 16, 2010 7:40 AM
    Friday, April 16, 2010 12:39 AM
  • This is the method I took. and it worked.

    Much debate yesterday on this. Thankyou for taking the time to respond

    Friday, April 16, 2010 7:40 AM