Results 1 to 6 of 6

Thread: [RESOLVED] Irritating Problem

  1. #1

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Resolved [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:
    1. Private Sub cmdGoogle_Click()
    2.        For i = 0 To lstBlocked.ListCount + 1
    3.             If UCase(cboSearch.Text) = UCase(lstBlocked.List(i)) Then
    4.                 wb1.Stop
    5.                 MsgBox "The Search Contains A Word That Is In The Block List."
    6.                 wb1.Stop
    7.                 Exit Sub
    8.                 Else: wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
    9.                                
    10.             ' Save - - Everything Above This Works Great
    11.             Dim X As Integer
    12.             Dim var1 As String
    13.             var1 = cboSearch.Text
    14.             For B = 0 To cboSearch.ListCount + 1
    15.                 If UCase(cboSearch.Text) = UCase(cobsearch.Text(B)) Then
    16.                     Exit Sub
    17.                 Else
    18.                 If var1 = "" Then Exit Sub Else
    19.                 cboSearch.AddItem var1
    20.                 Open App.Path & "\GoogleHistory.dat" For Output As #1
    21.                 For X = 0 To cboSearch.ListCount + 1
    22.                     Print #1, cboSearch.List(X)
    23.                 Next X
    24.                 Close #1
    25.                 End If
    26.         Next i
    27. End Sub
    Last edited by GedOfEarthsea; Sep 2nd, 2006 at 02:28 PM. Reason: spelling errors - lol

  2. #2

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    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:
    1. Private Sub cmdGoogle_Click()
    2.         For i = 0 To lstBlocked.ListCount + 1
    3.             If UCase(cboSearch.Text) = UCase(lstBlocked.List(i)) Then
    4.                 wb1.Stop
    5.                 MsgBox "The Search Contains A Word That Is In The Block List."
    6.                 wb1.Stop
    7.                 Exit Sub
    8.                 Else: wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
    9.                                
    10.             ' Save
    11.             Dim X As Integer
    12.             Dim var1 As String
    13.             var1 = cboSearch.Text
    14.             For B = 0 To cboSearch.ListCount + 1
    15.                 If UCase(cboSearch.Text) = UCase(cboSearch.List(B)) Then
    16.                     Exit Sub
    17.                 Else
    18.                 If var1 = "" Then Exit Sub Else
    19.                 cboSearch.AddItem var1
    20.                 Open App.Path & "\GoogleHistory.dat" For Output As #1
    21.                 For X = 0 To cboSearch.ListCount - 1
    22.                     Print #1, cboSearch.List(X)
    23.                 Next X
    24.                 Close #1
    25.                 End If
    26.             Next B
    27.             End If
    28.          Next i
    29. End Sub

    How would I make it so if I search again it won't add text already there?

  3. #3
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    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)?

  4. #4

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    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.

  5. #5
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: Irritating Problem

    try this..
    VB Code:
    1. Private Sub cmdGoogle_Click()
    2.     Dim i As Long
    3.     'search text for blocked
    4.     For i = 0 To lstBlocked.ListCount - 1
    5.         If InStr(cboSearch.Text, lstBlocked.List(i)) Then
    6.             MsgBox "The Search Contains A Word That Is In The Block List."
    7.             Exit Sub
    8.         End If
    9.     Next i
    10.     'make sure its not null
    11.     If Len(cboSearch.Text) = 0 Then
    12.         Exit Sub
    13.     End If
    14.     'no blocked word found in search string, so lets continue
    15.     wb1.Navigate ("http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=" & cboSearch)
    16.                    
    17.     ' Search to see if exists in combobox
    18.     For i = 0 To cboSearch.ListCount - 1
    19.         If UCase(cboSearch.Text) = UCase(cboSearch.List(i)) Then
    20.             Exit Sub
    21.         End If
    22.     Next i
    23.    
    24.     'doesnt exist so add it to top
    25.     cboSearch.AddItem cboSearch.Text, 0
    26.    
    27.     'save the new list
    28.     Open App.Path & "\GoogleHistory.dat" For Output As #1
    29.         For i = 0 To cboSearch.ListCount - 1
    30.             Print #1, cboSearch.List(i)
    31.         Next i
    32.     Close #1
    33.    
    34. End Sub

  6. #6

    Thread Starter
    Addicted Member GedOfEarthsea's Avatar
    Join Date
    May 2006
    Location
    USA
    Posts
    145

    Resolved 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
  •  



Click Here to Expand Forum to Full Width