[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.
Re: Timer Random Interval Question
VB Code:
Option Explicit
Private Sub Form_Load()
Dim cnt As Long
Randomize
For cnt = 1 To 20
Debug.Print RndVal(10, 0.5)
Next
Unload Me
End Sub
Public Function RndVal(Interval As Double, Offset As Double)
Dim dblBase As Double
dblBase = Interval - Offset
dblBase = dblBase + (2 * Offset * Rnd)
RndVal = Round(dblBase, 1)
End Function
Re: Timer Random Interval Question
Can you explain how i can format that into this code:
VB Code:
Private Sub cmdStart_Click()
txtInterval = Val(txtInterval)
If ErrorCheck1() = 1 Then
Exit Sub
End If
txtText.Enabled = False
txtInterval.Enabled = False
FrmClientMain.WebBrowser1.SetFocus
Timer1.Enabled = True
Timer1.Interval = Val(txtInterval.Text) * 1000
Me.Caption = "Auto Typer [Enabled]"
cmdStop.Enabled = True
cmdStart.Enabled = False
End Sub
Private Sub cmdStop_Click()
Timer1.Enabled = False
Me.Caption = "Auto Typer [Disabled]"
cmdStop.Enabled = False
cmdStart.Enabled = True
txtText.Enabled = True
txtInterval.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
end sub
Private Sub Timer1_Timer()
SendKeys strColor & strEffect & txtText + ("{Enter}")
End Sub
Re: Timer Random Interval Question
VB Code:
Private Sub cmdStart_Click()
txtInterval = Val(txtInterval)
If ErrorCheck1() = 1 Then
Exit Sub
End If
txtText.Enabled = False
txtInterval.Enabled = False
FrmClientMain.WebBrowser1.SetFocus
Timer1.Interval = RndVal(Val(txtInterval.Text), 0.5) * 1000
Timer1.Enabled = True
Me.Caption = "Auto Typer [Enabled]"
cmdStop.Enabled = True
cmdStart.Enabled = False
End Sub
Public Function RndVal(Interval As Double, Offset As Double) As Double
Dim dblBase As Double
dblBase = Interval - Offset
dblBase = dblBase + (2 * Offset * Rnd)
RndVal = Round(dblBase, 1)
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)
Re: Timer Random Interval Question
k i just added:
VB Code:
Timer1.Interval = RndVal(Val(txtInterval.Text), 0.5) * 1000
to my timer code and it appears to be working.