By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Loop not working in VB.NET

P: n/a
I am working on a project which tracks 'bad' words in IE and im using a
For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub

Thanks in advance

Nov 14 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a

Just thought id add. only the first word in the array is detected.. all
the others are ignored ifthat helps you solve the problem

Nov 14 '06 #2

P: n/a
InStr is (if I remember correctly) case sensitive, so make sure everything
matches in upper/lower case. Without seeing the code used to define and populate
BadWords(), it's hard to make guesses about what it contains.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
I am working on a project which tracks 'bad' words in IE and im using
a For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub
Thanks in advance

Nov 14 '06 #3

P: n/a
InStr is (if I remember correctly) case sensitive, so make sure everything
matches in upper/lower case.
Easiest way would be to convert all the "badwords" and the URL to
uppercase characters. I believe the command is .ToUpper (I don't have
vb on this machine)

Thanks,

Seth Rowe
Tim Patrick wrote:
InStr is (if I remember correctly) case sensitive, so make sure everything
matches in upper/lower case. Without seeing the code used to define and populate
BadWords(), it's hard to make guesses about what it contains.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
I am working on a project which tracks 'bad' words in IE and im using
a For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub
Thanks in advance
Nov 14 '06 #4

P: n/a
You might try:

Dim str as string = URL.ToString()
For Each s as string in BadWords
if InStr(str,s)>=0 then IE.Quit
next

--
Dennis in Houston
"jimmy" wrote:
I am working on a project which tracks 'bad' words in IE and im using a
For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub

Thanks in advance

Nov 15 '06 #5

P: n/a
I'm confused :-) Is the intent to check a list of "words" against a
complete URL e.g. www.essexhotel.com so the sequence "sex" (given it's
presence in the list) would mean that one couldn't view this site? I'm not
sure that will work so well as a strategy but given that is anybody checking
the docs on the InStr() method?

To the original poster... InStr() doesn't return a boolean right? So there
isn't much surprise there but let me suggest that you test your hypotheses
(in the future) rather than just write code. If is isn't working you might
try typing the following into the immediate window. I get an 11 as a return
value.... the boolean test is therefore out.

? microsoft.VisualBasic.InStr( "this is a test", "test")

And you will see that there is a CompareMethod parameter which if you don't
supply it defaults to the Option Compare setting. Would that setting be the
one you want?

And Dennis... meant 0 rather than >= 0 since 0 is returned in a number of
cases to indicate the string was not found.

Hope this helps...


"Dennis" <De****@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
You might try:

Dim str as string = URL.ToString()
For Each s as string in BadWords
if InStr(str,s)>=0 then IE.Quit
next

--
Dennis in Houston
"jimmy" wrote:
>I am working on a project which tracks 'bad' words in IE and im using a
For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub

Thanks in advance


Nov 15 '06 #6

P: n/a
Tom Leylan wrote:
To the original poster... InStr() doesn't return a boolean right? So there
isn't much surprise there but let me suggest that you test your hypotheses
(in the future) rather than just write code. If is isn't working you might
try typing the following into the immediate window. I get an 11 as a return
value.... the boolean test is therefore out.
You are correct, so the OP must be running without Option Strict On,
otherwise the compiler would have complained!

Nov 15 '06 #7

P: n/a
You are correct..I was thinking of IndexOf method. Also, the
String.Compare(a,b,True) = 0 would be a better solution to avoid case
problems.
--
Dennis in Houston
"Tom Leylan" wrote:
I'm confused :-) Is the intent to check a list of "words" against a
complete URL e.g. www.essexhotel.com so the sequence "sex" (given it's
presence in the list) would mean that one couldn't view this site? I'm not
sure that will work so well as a strategy but given that is anybody checking
the docs on the InStr() method?

To the original poster... InStr() doesn't return a boolean right? So there
isn't much surprise there but let me suggest that you test your hypotheses
(in the future) rather than just write code. If is isn't working you might
try typing the following into the immediate window. I get an 11 as a return
value.... the boolean test is therefore out.

? microsoft.VisualBasic.InStr( "this is a test", "test")

And you will see that there is a CompareMethod parameter which if you don't
supply it defaults to the Option Compare setting. Would that setting be the
one you want?

And Dennis... meant 0 rather than >= 0 since 0 is returned in a number of
cases to indicate the string was not found.

Hope this helps...


"Dennis" <De****@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
You might try:

Dim str as string = URL.ToString()
For Each s as string in BadWords
if InStr(str,s)>=0 then IE.Quit
next

--
Dennis in Houston
"jimmy" wrote:
I am working on a project which tracks 'bad' words in IE and im using a
For loop to check for an array of words in he address bar. I have
included the broken code below. Any pointers on why it isnt working
would be very useful.

Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef PostData
As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
Dim i As Integer
For i = 0 To BadWords.Length - 1
If InStr(URL.ToString(), BadWords(i)) Then
IE.Quit()
End If
Next
End Sub

Thanks in advance



Nov 16 '06 #8

P: n/a
When using the native VB string functions, you can use "Option Compare Text"
to avoid case issues as well.

Mike Ober.

"Dennis" <De****@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
You are correct..I was thinking of IndexOf method. Also, the
String.Compare(a,b,True) = 0 would be a better solution to avoid case
problems.
--
Dennis in Houston
"Tom Leylan" wrote:
I'm confused :-) Is the intent to check a list of "words" against a
complete URL e.g. www.essexhotel.com so the sequence "sex" (given it's
presence in the list) would mean that one couldn't view this site? I'm
not
sure that will work so well as a strategy but given that is anybody
checking
the docs on the InStr() method?

To the original poster... InStr() doesn't return a boolean right? So
there
isn't much surprise there but let me suggest that you test your
hypotheses
(in the future) rather than just write code. If is isn't working you
might
try typing the following into the immediate window. I get an 11 as a
return
value.... the boolean test is therefore out.

? microsoft.VisualBasic.InStr( "this is a test", "test")

And you will see that there is a CompareMethod parameter which if you
don't
supply it defaults to the Option Compare setting. Would that setting be
the
one you want?

And Dennis... meant 0 rather than >= 0 since 0 is returned in a number
of
cases to indicate the string was not found.

Hope this helps...


"Dennis" <De****@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
You might try:
>
Dim str as string = URL.ToString()
For Each s as string in BadWords
if InStr(str,s)>=0 then IE.Quit
next
>
--
Dennis in Houston
>
>
"jimmy" wrote:
>
>I am working on a project which tracks 'bad' words in IE and im using
a
>For loop to check for an array of words in he address bar. I have
>included the broken code below. Any pointers on why it isnt working
>would be very useful.
>>
>Private Sub BeginNavigate(ByVal pDisp As Object, ByRef URL As Object,
>ByRef Flags As Object, ByRef TargetFrameName As Object, ByRef
PostData
>As Object, ByRef Headers As Object, ByRef Cancel As Boolean)
> Dim i As Integer
> For i = 0 To BadWords.Length - 1
> If InStr(URL.ToString(), BadWords(i)) Then
> IE.Quit()
> End If
> Next
> End Sub
>>
>Thanks in advance
>>
>>


Nov 16 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.