dcsimg
Results 1 to 18 of 18

Thread: Search History

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Search History

    Is it possible in VB6 to have Search History for the textbox?
    For instance user enters 12345 into the search text box, clicks on button and the program executes SQL Statement something like SELECT ID FROM Table1 WHERE SecondField = '12345'. If record found the ID is displayed or used somewhere.
    Next time the user starts typing into the search thext box and gets that 12345 for selection. And so on till let's say 5 or 10 items saved in some file.

    Maybe ListBox or ComboBox should be used for this.

    I found some samples for VB.Net, but .Net text boxes have much bigger set of properties.

    Thank you

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,353

    Re: Search History

    Do you want to show "live" results when the user starts typing?
    When a previous entry was "12345" and the user types "12" then "12345" is shown?
    Or do you want the previous X entries shown in a listbox or combobox?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    Just Previous X items
    Thank you

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    And the search values should be stored locally in file, not in the database. Add latest values and remove the oldest one not to exceed X items

    Thank you

  5. #5
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    640

    Re: Search History

    A simple solution would be to place a ComboBox behind the TextBox so that the dropdown arrow bit "sticks out" at the end of the TextBox.

    When the button is clicked, add the current TextBox value to the list of items in the ComboBox (if it's not there already, of course).

    Regards, Phill W.

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,353

    Re: Search History

    Basic sample.
    Requires:
    TextBox named txtSearch
    ListBox names lstHistory
    CommandButton named cmdSearch

    Loading and saving of the History array is an exercise for the reader :-)
    Code:
    Option Explicit
    
    Private Const HISTORYSIZE As Long = 10
    
    Private m_lHistoryIndex As Long
    Private m_sHistory() As String
    
    Private Sub Form_Load()
      txtSearch.Text = ""
      lstHistory.Clear
    
      ReDim m_sHistory(HISTORYSIZE - 1)
    End Sub
    
    Private Sub cmdSearch_Click()
      Dim sSearch As String
      
      sSearch = Trim$(txtSearch.Text)
      m_sHistory(m_lHistoryIndex) = sSearch
      m_lHistoryIndex = (m_lHistoryIndex + 1) Mod HISTORYSIZE
      pSearch sSearch
      pShowHistory
    End Sub
    
    Private Sub lstHistory_Click()
      pSearch lstHistory.Text
    End Sub
    
    Private Sub pShowHistory()
      Dim i As Long
      
      With lstHistory
        .Clear
        For i = 0 To HISTORYSIZE - 1
          If Len(m_sHistory(i)) > 0 Then
            lstHistory.AddItem m_sHistory(i)
          End If
        Next i
      End With
    End Sub
    
    Private Sub pSearch(ByVal sSearch As String)
      ' do what you need to do
      MsgBox "You searched for: " & vbLf & sSearch, vbInformation + vbOKOnly
    End Sub

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    Quote Originally Posted by Arnoutdv View Post
    Basic sample.

    Loading and saving of the History array is an exercise for the reader :-)
    Thank you

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    Thank you. I will try

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,660

    Re: Search History

    Why not just use a Combobox in Textbox-Mode?
    everytime he commits his search, it's added to the (hidden) combolist (validate on duplicates!) on first position.
    check listcount. If it exceeds X items remove the last one
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    I do not see Textbox Mode in the list of Combobox properties.
    Can you provide more details please?

    Thank you

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    I do not see Textbox Mode in the list of Combobox properties.
    Can you provide more details please?

    Thank you

  12. #12
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    297

    Re: Search History

    I have a usercontrol I use for that task might fit what your looking for

    https://github.com/dzzie/libs/tree/master/historycombo

    Code:
    Private Sub Form_Load()
        hc.LoadHistory App.path & "\hc.dat"
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        hc.SaveHistory
    End Sub
    
    Private Sub cmdDoit_Click()
        hc.RecordIfNew
    End Sub
    
    Private Sub Command1_Click()
        hc.ClearHistory
    End Sub

  13. #13
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    640

    Re: Search History

    I suspect Zvoni means "DropDown", not "Textbox-Mode".

    Code:
    Combo1.Style = vbDropDown
    With this set, you can pick from the items in the list or enter a completely new value.

    Regards, Phill W.

  14. #14
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,660

    Re: Search History

    Quote Originally Posted by Phill.W View Post
    I suspect Zvoni means "DropDown", not "Textbox-Mode".

    Code:
    Combo1.Style = vbDropDown
    With this set, you can pick from the items in the list or enter a completely new value.

    Regards, Phill W.
    Partially,
    but i fear i stepped again into the trap with the differences for Comboboxes in VB6 and Office-VBA.
    In Office-VBA i can set up a ComboBox as follows:
    Style = DropDown (as mentiond by Phil)
    ShowDropButtonWhen=0 - ShowNever
    Then it's in "TextBox"-mode with all the Properties of a ComboBox.
    As i said a few times: It's been years, since i fired up VB6, so forgive me if i confuse a few things

    but i just reserached it in the Docs: You could subclass that combobox.
    https://docs.microsoft.com/en-us/win...agcomboboxinfo
    Use the STATE_SYSTEM_INVISIBLE
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    Thanks a lot for all responces. I'll combine advices and create something

  16. #16
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,465

    Re: Search History

    Deleted
    Last edited by Eduardo-; Mar 15th, 2019 at 07:24 PM.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2014
    Posts
    274

    Re: Search History

    It is interesting sample, just too complex for me.
    Thank you very much

  18. #18
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,465

    Re: Search History

    Quote Originally Posted by chapran View Post
    It is interesting sample, just too complex for me.
    Thank you very much
    Anyway I removed the project because there were some bugs.
    Last edited by Eduardo-; Mar 15th, 2019 at 07:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width