I have never used loops before so i dont know where to begin, i looked on the internet an found this code but it doesnt work
How do you loop a timer?VB Code:
Do While Timer1.Enabled DoEvents Loop
Printable View
I have never used loops before so i dont know where to begin, i looked on the internet an found this code but it doesnt work
How do you loop a timer?VB Code:
Do While Timer1.Enabled DoEvents Loop
Of course it works ;) Add a Timer on your form and try this (it should end the loop after 3 seconds - .Interval):
VB Code:
Option Explicit Private Sub Form_Load() With Timer1 .Interval = 3000 .Enabled = True End With 'this means loop while Timer1.Enabled = True 'in other words, end the loop when Timer1.Enabled = False Do While Timer1.Enabled DoEvents Loop Debug.Print "Loop ended" End Sub Private Sub Timer1_Timer() Timer1.Enabled = False End Sub
As gavio said, what you have should work.
What are you trying to accomplish that isn't working?
This is the code i have now. I have created mt own browser and now i am trying to block access to some sites. It still dosent work do you know what i am doin wrong.
VB Code:
With Timer5 .Interval = 3000 .Enabled = True End With 'this means loop while Timer1.Enabled = True 'in other words, end the loop when Timer1.Enabled = False Do While Timer1.Enabled DoEvents Loop Debug.Print "Loop ended" Timer5.Enabled = True End Sub
VB Code:
Private Sub Timer5_Timer() If Timer5.interval + 1 Then check End If End Sub
VB Code:
Private Sub check() If txtWebsite.Text = "http://www.google.com" Then MsgBox "Your System Administrator has disallowed access to this site as the content is inappropiate." 'home txtWebsite.Text = frmOptions.txtHome.Text WB1.Navigate txtWebsite.Text End If End Sub
What are you trying to accomplish with your timer loop that isn't working?
It doesn't work cause Timer5 is never "disabled". When you'll do that the loop will end. Also, you have Timer1 in your loop but you're using Timer5.
i dont want the timer to be disabled untill the form is closed as it checks to see if the address bar contains the text "http://google.com" every 3 seconds.
If it does then it will go to the homepage.
So remove the loop - all it does it wait until the timer is disabled.
The sub Timer5_Timer will automatically re-run every 3 seconds (3000ms), as that is what you set the Interval to.
I can't see a reason for the If statement in the Timer5_Timer sub either (or what you actually wanted to check with it).
The way I see it, your code should be like this:
VB Code:
With Timer5 .Interval = 3000 .Enabled = True End With End Sub(check would stay as it is).VB Code:
Private Sub Timer5_Timer() check End Sub
If this doesn't do what you want, then tell us what you want different, and we'll explain how to do it.
it still dosent work
i'm tring to make a site blocker that blocks sites, the timer is suppose to run the check command every 3 secs to see if the text in the address bar is http://www.google.com, if it is then it will show a message box and go to the home page.
The sub Timer5_Timer will run every 3 seconds. If you want to test, put a MsgBox in there.
I would guess that the check routine is the problem, as (for whatever reason) txtWebsite.Text is not exactly equal to "http://www.google.com".
I would recommend removing any spaces from both sides of the text you are checking, and converting it to lowercase, like this:
..if that doesn't work, what is in txtWebsite.Text?VB Code:
If LCase(Trim(txtWebsite.Text)) = "http://www.google.com" Then
Thanks everyone, its working now.
Do you think i coud add an access 97 database to the code so it will search through the database.
You certainly could.
See the ADO Tutorial link in my signature for how to use an Access database from VB, and the "Further Steps" link (within the ADO tutorial) for how to find a record with specific data.