Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys ,
i do have a problem with putting a value for x. I want to make a timer with interval x that will equal to value appeard in textbox1 . What code should i use ?
Posted
Comments
Tim Corey 12-Jul-12 8:46am    
Please explain your question. Right now it is very confusing. Could you also show us an example of what you mean?
Zlatan1994 12-Jul-12 8:57am    
TextBox1.Text = RandX.Next(195, 205) That s my random number in textbox1.text
And i want to use it in timer . So i decided to put value x = textbox1.text but it s not working
bbirajdar 12-Jul-12 9:05am    
x should be a number right? Did you try typecasting it?
Zlatan1994 12-Jul-12 9:24am    
no
Zlatan1994 12-Jul-12 9:25am    
i dont know how to type cast it

Since you have a value in a text box that you want to use as the timer interval, you need to convert that textbox value to an integer before assigning it to the timer value. For example, you could do it like this:

C#
TextBox1.Text = RandX.Next(195, 205);
int timerNumber = Convert.ToInt32(TextBox1.Text);
yourTimer.Interval = timerNumber;

Update
Based upon the comments below, this is how your code should look:
VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim RandX As New Random

    TextBox1.Text = RandX.Next(195, 205)
    Dim timerNumber As Integer = Convert.ToInt32(TextBox1.Text)
    Timer2.Interval = timerNumber

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    mouse_event(mouseclickdown, 0, 0, 0, 0)
    mouse_event(mouseclickup, 0, 0, 0, 0)
End Sub

The one thing to pay attention to, though, is that Timer2 is assumed to already be running. That might not be what you want. If not, you should probably stop Timer2 after it runs and start it once you set the interval in Timer1. Something like this:
VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Dim RandX As New Random

    TextBox1.Text = RandX.Next(195, 205)
    Dim timerNumber As Integer = Convert.ToInt32(TextBox1.Text)
    Timer2.Interval = timerNumber
    Timer2.Start()

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    mouse_event(mouseclickdown, 0, 0, 0, 0)
    mouse_event(mouseclickup, 0, 0, 0, 0)
    Timer2.Stop()
End Sub
 
Share this answer
 
v2
Comments
Zlatan1994 12-Jul-12 9:21am    
int timerNumber = Convert.ToInt32(TextBox1.Text);
yourTimer.Interval = timerNumber;

don t know where to put this bucouse yourtimer.interval is not running
Tim Corey 12-Jul-12 9:27am    
That is pseudo-code. You would need to put the timerNumber value into your timer, whatever it is named. If you don't have a timer, you would need to create one. I just showed you what it would look like to assign a timer a new interval. Does that help?
Zlatan1994 12-Jul-12 9:32am    
well i don t know how to put timernumber value to my timer. i already have 2 timers this is first one Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim RandX As New Random

TextBox1.Text = RandX.Next(195, 205)

and this is second one Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
mouse_event(mouseclickdown, 0, 0, 0, 0)
mouse_event(mouseclickup, 0, 0, 0, 0)
Zlatan1994 12-Jul-12 9:33am    
now where should i put the code u wrote
Tim Corey 12-Jul-12 9:41am    
I've updated my solution based upon these comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900