[RESOLVED] Detect words in a listbox (Resolved)
Hi,
I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.
VB Code:
Private Sub Command1_Click()
For b = 0 To frmSetup.Lstblock.ListCount
If Text1.Text = frmSetup.Lstblock.List(b) Then
MsgBox ("Word is not allowed")
Else
If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
Exit Sub
End If
End If
Next b
frmSetup.Show
End Sub
This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
Re: Detect words in a listbox
Quote:
Originally posted by Nightwalker83
Hi,
I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.
VB Code:
Private Sub Command1_Click()
For b = 0 To frmSetup.Lstblock.ListCount
If Text1.Text = frmSetup.Lstblock.List(b) Then
MsgBox ("Word is not allowed")
Else
If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
Exit Sub
End If
End If
Next b
frmSetup.Show
End Sub
This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
u can use API..
VB Code:
'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Add some items to the listbox
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub
Private Sub Text1_Change()
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub
Re: Detect words in a listbox
Quote:
Originally posted by Nightwalker83
Hi,
I am trying to detect words that are in a listbox by typing a word in a textbox then click if the word is in the box.
VB Code:
Private Sub Command1_Click()
For b = 0 To frmSetup.Lstblock.ListCount
If Text1.Text = frmSetup.Lstblock.List(b) Then
MsgBox ("Word is not allowed")
Else
If Not Text1.Text = Text1.Text & frmSetup.Lstblock.List(b) Then
Exit Sub
End If
End If
Next b
frmSetup.Show
End Sub
This code works only when I type in the word that is the first word listed in the listbox. How can I make in so it checks for all the wors typed into the listbox?
u can use API..
VB Code:
'This project needs a ListBox, named List1 and a TextBox, named Text1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Add some items to the listbox
With List1
.AddItem "Computer"
.AddItem "Screen"
.AddItem "Modem"
.AddItem "Printer"
.AddItem "Scanner"
.AddItem "Sound Blaster"
.AddItem "Keyboard"
.AddItem "CD-Rom"
.AddItem "Mouse"
End With
End Sub
Private Sub Text1_Change()
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
End Sub
Cheers...