473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Loop not working in VB.NET

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
8 1680

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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ken Fine | last post by:
I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop, and it ain't working -- I'm getting a syntax error....
8
by: Drew | last post by:
I am building an application for keeping track of user permissions here at work. I have built the interfaces, and am now working on the processing page for inserting to the database. I am having...
8
by: Hardrock | last post by:
I encountered some difficulty in implementing dynamic loop nesting. I.e. the number of nesting in a for(...) loop is determined at run time. For example void f(int n) { For(i=0; i<=K; i++)...
5
by: L. Oborne | last post by:
I have this code working fine in Classic ASP but I get compile errors when I try to run it as ASP.NET. Do While NOT RS.EOF If ... Then... Else... End If RS.MoveNext Loop
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
by: mrjoka | last post by:
hi experts, i'm developing a page in ASP but i'm doing also some javascript insode the page. i'm creating a frame and i want to loop this frame with a duplicateloop function so the form will be...
2
by: d3vkit | last post by:
Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies. I am using PHP5 with...
6
by: uche | last post by:
This function that I have implemented gives me an infinite loop. I am trying to produce a hexdum program, however, this function is not functioning correctly.....Please help. void...
4
by: joaotsetsemoita | last post by:
hello everyone. Im trying to time out a loot after a certain time. Probably 5 to 10 minutes. I have the following function Private Sub processFileCreation(ByVal source As Object, ByVal e As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.