|
-
Nov 10th, 2006, 08:11 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Simple Loop question i think
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
VB Code:
Do While Timer1.Enabled
DoEvents
Loop
How do you loop a timer?
-
Nov 10th, 2006, 08:19 AM
#2
Re: Simple Loop question i think
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
-
Nov 10th, 2006, 08:26 AM
#3
Re: Simple Loop question i think
As gavio said, what you have should work.
What are you trying to accomplish that isn't working?
-
Nov 10th, 2006, 08:37 AM
#4
Thread Starter
Hyperactive Member
Re: Simple Loop question i think
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
-
Nov 10th, 2006, 09:16 AM
#5
Re: Simple Loop question i think
What are you trying to accomplish with your timer loop that isn't working?
-
Nov 10th, 2006, 09:22 AM
#6
Re: Simple Loop question i think
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.
-
Nov 10th, 2006, 10:05 AM
#7
Thread Starter
Hyperactive Member
Re: Simple Loop question i think
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.
-
Nov 10th, 2006, 11:09 AM
#8
Re: Simple Loop question i think
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
VB Code:
Private Sub Timer5_Timer()
check
End Sub
(check would stay as it is).
If this doesn't do what you want, then tell us what you want different, and we'll explain how to do it.
-
Nov 10th, 2006, 11:54 AM
#9
Thread Starter
Hyperactive Member
Re: Simple Loop question i think
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.
-
Nov 10th, 2006, 12:02 PM
#10
Re: Simple Loop question i think
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:
VB Code:
If LCase(Trim(txtWebsite.Text)) = "http://www.google.com" Then
..if that doesn't work, what is in txtWebsite.Text?
-
Nov 10th, 2006, 12:11 PM
#11
Thread Starter
Hyperactive Member
Re: Simple Loop question i think
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.
-
Nov 10th, 2006, 12:15 PM
#12
Re: [RESOLVED] Simple Loop question i think
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.
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
|