|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Loop not working in VB.NETI 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 Just thought id add. only the first word in the array is detected.. all
the others are ignored ifthat helps you solve the problem 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 Show quoteHide quote > 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 > > InStr is (if I remember correctly) case sensitive, so make sure everything Easiest way would be to convert all the "badwords" and the URL to> matches in upper/lower case. uppercase characters. I believe the command is .ToUpper (I don't have vb on this machine) Thanks, Seth Rowe Tim Patrick wrote: Show quoteHide quote > 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 > > 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 -- Show quoteHide quoteDennis 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 > > 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... Show quoteHide quote "Dennis" <Den***@discussions.microsoft.com> wrote in message news:A66C81C0-8015-4EB4-ABE7-DC5AC807DAAE@microsoft.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 >> >> Tom Leylan wrote:
> To the original poster... InStr() doesn't return a boolean right? So there You are correct, so the OP must be running without Option Strict On,> 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. otherwise the compiler would have complained! 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. -- Show quoteHide quoteDennis 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" <Den***@discussions.microsoft.com> wrote in message > news:A66C81C0-8015-4EB4-ABE7-DC5AC807DAAE@microsoft.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 > >> > >> > > > When using the native VB string functions, you can use "Option Compare Text"
to avoid case issues as well. Mike Ober. Show quoteHide quote "Dennis" <Den***@discussions.microsoft.com> wrote in message news:CED55C80-A2AF-4607-8FA0-70BECDE3953E@microsoft.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" <Den***@discussions.microsoft.com> wrote in message > > news:A66C81C0-8015-4EB4-ABE7-DC5AC807DAAE@microsoft.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 > > >> > > >> > > > > > > >
.NET Serialization Quest
Sound with New System.Media.SoundPlayer() Directory.Getfiles search pattern New SQL Express 2005 ? Control Arrays Office 2007 controls Is there a shortcut for class properties? Get Product Keys How to detect total CPU percentage utilization Multithreaded application, thread not quiting. |
|||||||||||||||||||||||