Results 1 to 5 of 5

Thread: [RESOLVED]Timer Random Interval Question

  1. #1

    Thread Starter
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Resolved [RESOLVED]Timer Random Interval Question

    How can i make it so my timer can randomly be off by .5 of a second either slow or fast. Ex:
    Interval=10
    Possible Randoms=9.5, 9.6, 9.7, 9.8, 9.9, 10, 10.1, 10.2, 10.3, 10.4, 10.5

    Can anyone please help me.

    P.S. the interval of the timer is specified by the user so it could be changed after they stopped the timer.
    Last edited by Mxjerrett; Nov 26th, 2006 at 01:38 PM.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Timer Random Interval Question

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim cnt As Long
    5.  
    6.    Randomize
    7.    For cnt = 1 To 20
    8.       Debug.Print RndVal(10, 0.5)
    9.    Next
    10.    Unload Me
    11. End Sub
    12.  
    13. Public Function RndVal(Interval As Double, Offset As Double)
    14. Dim dblBase As Double
    15.    
    16.    dblBase = Interval - Offset
    17.    dblBase = dblBase + (2 * Offset * Rnd)
    18.    RndVal = Round(dblBase, 1)
    19. End Function
    Last edited by leinad31; Nov 26th, 2006 at 03:31 AM.

  3. #3

    Thread Starter
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Timer Random Interval Question

    Can you explain how i can format that into this code:

    VB Code:
    1. Private Sub cmdStart_Click()
    2. txtInterval = Val(txtInterval)
    3. If ErrorCheck1() = 1 Then
    4. Exit Sub
    5. End If
    6. txtText.Enabled = False
    7. txtInterval.Enabled = False
    8. FrmClientMain.WebBrowser1.SetFocus
    9. Timer1.Enabled = True
    10. Timer1.Interval = Val(txtInterval.Text) * 1000
    11. Me.Caption = "Auto Typer [Enabled]"
    12. cmdStop.Enabled = True
    13. cmdStart.Enabled = False
    14. End Sub
    15. Private Sub cmdStop_Click()
    16. Timer1.Enabled = False
    17. Me.Caption = "Auto Typer [Disabled]"
    18. cmdStop.Enabled = False
    19. cmdStart.Enabled = True
    20. txtText.Enabled = True
    21. txtInterval.Enabled = True
    22. End Sub
    23.  
    24.  
    25.  
    26. Private Sub Form_Load()
    27. Timer1.Enabled = False
    28. end sub
    29.  
    30. Private Sub Timer1_Timer()
    31. SendKeys strColor & strEffect & txtText + ("{Enter}")
    32. End Sub

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  4. #4
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Timer Random Interval Question

    VB Code:
    1. Private Sub cmdStart_Click()
    2.    txtInterval = Val(txtInterval)
    3.    If ErrorCheck1() = 1 Then
    4.       Exit Sub
    5.    End If
    6.    txtText.Enabled = False
    7.    txtInterval.Enabled = False
    8.    FrmClientMain.WebBrowser1.SetFocus
    9.    Timer1.Interval = RndVal(Val(txtInterval.Text), 0.5) * 1000
    10.    Timer1.Enabled = True
    11.    Me.Caption = "Auto Typer [Enabled]"
    12.    cmdStop.Enabled = True
    13.    cmdStart.Enabled = False
    14. End Sub
    15.  
    16. Public Function RndVal(Interval As Double, Offset As Double) As Double
    17. Dim dblBase As Double
    18.    
    19.    dblBase = Interval - Offset
    20.    dblBase = dblBase + (2 * Offset * Rnd)
    21.    RndVal = Round(dblBase, 1)
    22. End Function
    Don't forget Randomize on Form_Load(). If code above throws an error try updating with

    Timer1.Interval = CInt(RndVal(Val(txtInterval.Text), 0.5) * 1000)

  5. #5

    Thread Starter
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Timer Random Interval Question

    k i just added:
    VB Code:
    1. Timer1.Interval = RndVal(Val(txtInterval.Text), 0.5) * 1000

    to my timer code and it appears to be working.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width