-
Mar 14th, 2019, 09:36 AM
#1
Thread Starter
Hyperactive Member
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
-
Mar 14th, 2019, 09:50 AM
#2
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?
-
Mar 14th, 2019, 09:52 AM
#3
Thread Starter
Hyperactive Member
Re: Search History
Just Previous X items
Thank you
-
Mar 14th, 2019, 09:54 AM
#4
Thread Starter
Hyperactive Member
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
-
Mar 14th, 2019, 09:58 AM
#5
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.
-
Mar 14th, 2019, 10:07 AM
#6
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
-
Mar 14th, 2019, 10:51 AM
#7
Thread Starter
Hyperactive Member
Re: Search History
Originally Posted by Arnoutdv
Basic sample.
Loading and saving of the History array is an exercise for the reader :-)
Thank you
-
Mar 14th, 2019, 10:53 AM
#8
Thread Starter
Hyperactive Member
-
Mar 14th, 2019, 03:48 PM
#9
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE 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.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Mar 14th, 2019, 03:52 PM
#10
Thread Starter
Hyperactive Member
Re: Search History
I do not see Textbox Mode in the list of Combobox properties.
Can you provide more details please?
Thank you
-
Mar 14th, 2019, 03:53 PM
#11
Thread Starter
Hyperactive Member
Re: Search History
I do not see Textbox Mode in the list of Combobox properties.
Can you provide more details please?
Thank you
-
Mar 14th, 2019, 06:22 PM
#12
Last edited by dz32; Apr 26th, 2019 at 11:06 AM.
-
Mar 15th, 2019, 02:57 AM
#13
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.
-
Mar 15th, 2019, 03:51 AM
#14
Re: Search History
Originally Posted by Phill.W
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE 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.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Mar 15th, 2019, 08:59 AM
#15
Thread Starter
Hyperactive Member
Re: Search History
Thanks a lot for all responces. I'll combine advices and create something
-
Mar 15th, 2019, 06:11 PM
#16
Last edited by Eduardo-; Mar 15th, 2019 at 07:24 PM.
-
Mar 15th, 2019, 06:20 PM
#17
Thread Starter
Hyperactive Member
Re: Search History
It is interesting sample, just too complex for me.
Thank you very much
-
Mar 15th, 2019, 07:20 PM
#18
Re: Search History
Originally Posted by chapran
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|