|
-
Sep 2nd, 2006, 02:25 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Irritating Problem
Hello, I am stuck. I noticed in one of my older programs I have a problem and I wanted to fix it.
It is a web browser. I added a google search button to it. When the button is pressed I wanted to save the text to file for a history in the google search combobox. That works, however it adds it 5 times each time it is searched! I have no idea why, so today I have tried to make it exit the saving sub if the text is already in there. I keep getting errors or it just keeps doing it. If someone could please help me it would be wonderful, I added the code for the whole command click below.
VB Code:
Private Sub cmdGoogle_Click()
For i = 0 To lstBlocked.ListCount + 1
If UCase(cboSearch.Text) = UCase(lstBlocked.List(i)) Then
wb1.Stop
MsgBox "The Search Contains A Word That Is In The Block List."
wb1.Stop
Exit Sub
Else: wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
' Save - - Everything Above This Works Great
Dim X As Integer
Dim var1 As String
var1 = cboSearch.Text
For B = 0 To cboSearch.ListCount + 1
If UCase(cboSearch.Text) = UCase(cobsearch.Text(B)) Then
Exit Sub
Else
If var1 = "" Then Exit Sub Else
cboSearch.AddItem var1
Open App.Path & "\GoogleHistory.dat" For Output As #1
For X = 0 To cboSearch.ListCount + 1
Print #1, cboSearch.List(X)
Next X
Close #1
End If
Next i
End Sub
Last edited by GedOfEarthsea; Sep 2nd, 2006 at 02:28 PM.
Reason: spelling errors - lol
-
Sep 2nd, 2006, 02:46 PM
#2
Thread Starter
Addicted Member
Re: Irritating Problem
I managed to fix the problem halfway, now it only adds one of the text each time instead of 5. But now if you search for something already there it still adds it in again.
VB Code:
Private Sub cmdGoogle_Click()
For i = 0 To lstBlocked.ListCount + 1
If UCase(cboSearch.Text) = UCase(lstBlocked.List(i)) Then
wb1.Stop
MsgBox "The Search Contains A Word That Is In The Block List."
wb1.Stop
Exit Sub
Else: wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
' Save
Dim X As Integer
Dim var1 As String
var1 = cboSearch.Text
For B = 0 To cboSearch.ListCount + 1
If UCase(cboSearch.Text) = UCase(cboSearch.List(B)) Then
Exit Sub
Else
If var1 = "" Then Exit Sub Else
cboSearch.AddItem var1
Open App.Path & "\GoogleHistory.dat" For Output As #1
For X = 0 To cboSearch.ListCount - 1
Print #1, cboSearch.List(X)
Next X
Close #1
End If
Next B
End If
Next i
End Sub
How would I make it so if I search again it won't add text already there?
-
Sep 2nd, 2006, 03:36 PM
#3
Hyperactive Member
Re: Irritating Problem
im trying to make sense of your code so i must ask a few questions.
1. do you want all the items in cbosearch to be used in google at once, or just the selected listindex of cbosearch? the reason why i ask that is because it looks like you are trying to save the contents of cbosearch in a file, but its only searching for 1 listindex?
2. why does your code tell the procedure to exit sub when it finds the selected listindex and print the rest of it to a file (until it finds it)?
-
Sep 2nd, 2006, 03:44 PM
#4
Thread Starter
Addicted Member
Re: Irritating Problem
1. I am trying to save it to text file and after it saves I want it to search for what it just saved, ie: I typed "Visual Basic" I want that to be added to the combobox and saved to the file, then I want it to be searched.
2. I'm trying to make it cancel saving it if it was already saved, but I really have no idea what I am doing.
-
Sep 2nd, 2006, 04:12 PM
#5
Hyperactive Member
Re: Irritating Problem
try this..
VB Code:
Private Sub cmdGoogle_Click()
Dim i As Long
'search text for blocked
For i = 0 To lstBlocked.ListCount - 1
If InStr(cboSearch.Text, lstBlocked.List(i)) Then
MsgBox "The Search Contains A Word That Is In The Block List."
Exit Sub
End If
Next i
'make sure its not null
If Len(cboSearch.Text) = 0 Then
Exit Sub
End If
'no blocked word found in search string, so lets continue
wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
' Search to see if exists in combobox
For i = 0 To cboSearch.ListCount - 1
If UCase(cboSearch.Text) = UCase(cboSearch.List(i)) Then
Exit Sub
End If
Next i
'doesnt exist so add it to top
cboSearch.AddItem cboSearch.Text, 0
'save the new list
Open App.Path & "\GoogleHistory.dat" For Output As #1
For i = 0 To cboSearch.ListCount - 1
Print #1, cboSearch.List(i)
Next i
Close #1
End Sub
-
Sep 2nd, 2006, 04:16 PM
#6
Thread Starter
Addicted Member
Re: Irritating Problem
Thanks a lot you solved my problem
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
|