|
-
Nov 26th, 2006, 12:49 AM
#1
Thread Starter
Fanatic Member
[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.
-
Nov 26th, 2006, 03:26 AM
#2
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
Last edited by leinad31; Nov 26th, 2006 at 03:31 AM.
-
Nov 26th, 2006, 12:35 PM
#3
Thread Starter
Fanatic Member
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
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.
-
Nov 26th, 2006, 01:00 PM
#4
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)
-
Nov 26th, 2006, 01:25 PM
#5
Thread Starter
Fanatic Member
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|