|
-
Dec 13th, 1999, 11:30 PM
#1
Thread Starter
Hyperactive Member
Let's say I have an array called sValid().
I want to make a combobox that the user can only type in string that are inside sValid()
If a user tries to type in a string that is not in the array nothing should happen....
Example:
User tries to type in "testing"
This is possible because the array contains a string "testing"
Now, when the user tries to type in "testings" the result in the combobox text should be "testing"
How do I do this
-
Dec 14th, 1999, 01:45 AM
#2
Try this:
Code:
Option Explicit
Private sValid() As String
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim strText As String
Dim i As Integer
Dim bIsFound As Boolean
If KeyAscii = 8 Then Exit Sub
strText = Combo1.Text & Chr(KeyAscii)
For i = 0 To UBound(sValid)
If InStr(UCase(sValid(i)), UCase(strText)) Then
bIsFound = True
End If
Next
If Not bIsFound Then KeyAscii = 0
End Sub
Private Sub Form_Load()
ReDim Preserve sValid(2)
sValid(0) = "Setting"
sValid(1) = "Close"
sValid(2) = "Testing"
Combo1.Text = ""
End Sub
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
-
Dec 14th, 1999, 05:05 AM
#3
Member
Set ComboBox style to 2-Dropdown List, and add all array items to comboBox.
Code:
Private Sub Form_Load()
myArr(0) = "Setting"
myArr(1) = "Close"
myArr(2) = "Testing"
LoadCombo Combo1, myArr
End Sub
Private Sub LoadCombo(cb As ComboBox, arr As Variant)
Dim i As Integer
cb.Clear
For i = 0 To UBound(arr)
cb.AddItem arr(i)
Next
End Sub
Joon
-
Dec 14th, 1999, 12:05 PM
#4
Lively Member
You could change this style of the combo to "dropdown list" and the user will only be able to select what is in the list. I you really need to let them type stuff in then this should work,
Drop a combo onto a form and paste the following code
Option Explicit
Dim sArray(2) As String
Private Sub Combo1_Change()
Dim i As Integer
Dim sCompare As String
Dim bOk As Boolean
sCompare = Combo1.Text
For i = 0 To UBound(sArray)
If Len(sArray(i)) >= Len(sCompare) Then
If Left(sArray(i), Len(sCompare)) = sCompare Then
bOk = True
Exit For
End If
End If
Next
If Not bOk Then
If Len(Combo1.Text) > 1 Then
Combo1.Text = Left(Combo1.Text, Len(Combo1.Text) - 1)
Else
Combo1.Text = ""
End If
End If
Combo1.SelStart = Len(Combo1.Text)
End Sub
Private Sub Form_Load()
Dim i As Integer
sArray(0) = "one"
sArray(1) = "two"
sArray(2) = "three"
For i = 0 To 2
Combo1.AddItem sArray(i)
Next
End Sub
-
Dec 14th, 1999, 06:22 PM
#5
Thread Starter
Hyperactive Member
Thanx Serge,
Works like a charm...
-
Dec 14th, 1999, 07:17 PM
#6
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
|