|
-
Oct 14th, 2000, 05:59 PM
#1
Thread Starter
Addicted Member
is there a way when you press like a in a text box you can go to the a's in the combo box ex
user :
Hel
combobox: hello
is there a way to do this in vb
WHat would we do with out Microsoft.
A lot more.
-
Oct 14th, 2000, 06:20 PM
#2
Frenzied Member
I remember denniswrenn answered this a while ago, I'll show him this post for ya
-
Oct 14th, 2000, 06:37 PM
#3
Thread Starter
Addicted Member
WHat would we do with out Microsoft.
A lot more.
-
Oct 14th, 2000, 06:44 PM
#4
Fanatic Member
It seems to be something simple. I'm throwing together a sample and I'll post it when I'm done.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Oct 14th, 2000, 08:27 PM
#5
Thread Starter
Addicted Member
how do i use the ShellExecute to open a html page thanks
WHat would we do with out Microsoft.
A lot more.
-
Oct 14th, 2000, 08:29 PM
#6
Fanatic Member
Here's a sample that does what you asked about. I could have done a binary search function, but then I realized it would be simpler to build a string from the first letter of the combobox contents and use InStr instead. Paste this into a project with a combobox (Combo1) and a textbox (Text1). Remember to set the Sorted property of the combobox to True in the Properties window before you run this, or it won't work correctly.
Code:
Option Explicit
Private Sub Form_Load()
'some test things
Combo1.AddItem "apple"
Combo1.AddItem "aardvark"
Combo1.AddItem "banana"
Combo1.AddItem "ball"
Combo1.AddItem "cherry"
Combo1.AddItem "doorknob"
Combo1.AddItem "eggplant"
Combo1.AddItem "easy"
Combo1.AddItem "test"
Combo1.AddItem "fruit"
End Sub
Private Function Find(Target As ComboBox, SearchKey As String) As Integer
Dim SearchDomain As String
Dim Position As Integer
Dim i As Integer
SearchDomain = ""
SearchKey = LCase$(SearchKey) 'remove case-sensitivity
Find = -1 'default is not finding anything
'if there's nothing in the combobox, leave function
If Target.ListCount = 0 Then Exit Function
'cycle through all items in the combobox, building a
'string using the first char of each item
For i = 0 To (Target.ListCount - 1)
SearchDomain = SearchDomain & LCase$(Left$(Target.List(i), 1))
Next i
'look for the first position of the desired key in the string
Position = InStr(SearchDomain, SearchKey)
'if it was found, return the position in the combobox corresponding
'to the found position (items in a combobox go from 0 to ComboBox.ListCount-1
If Position > 0 Then Find = Position - 1
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim NewIndex As Integer
'try to find the pressed key in the combobox
NewIndex = Find(Combo1, Chr$(KeyAscii))
'if found, change the combobox's currently selected index and text to show it
If NewIndex <> -1 Then
Combo1.ListIndex = NewIndex
Combo1.Text = Combo1.List(Combo1.ListIndex)
End If
End Sub
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Oct 14th, 2000, 10:08 PM
#7
Frenzied Member
Aw man! InStr! I tried making a sample for ya on my own (failed) and I tried Left (what was I thinking!) apparently dennis hasn't been on yet...oh well
-
Oct 15th, 2000, 12:00 AM
#8
Fanatic Member
Yeah, I almost smacked myself when I realized I could make VB do the hard work. I was trying to make a binary search function, but had no success. I couldn't recall how to make the search thing drop into the "lower" half of the set, and of course that's 50% of the whole algorithm heh heh.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
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
|