473,394 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Compare text in a combobox

Hello,
I'm trying to get te index of a specific text in a ComboBox.
The ComboBox is filled by searching for filenames in a directory.
The text of the last item selected in the ComboBox is saved in a
textfile in the OnExit Event of the Mainform.
While loading the Mainform I want the text that was saved in the file
to be compared with the items in the ComboBox ad get the index of the
found item, so that I can set it as selected.

I thought i could do it something like this, but the program hangs
before I can see anything.
---------
Code
---------
Dim i, As Integer
Dim line As String
For i = 0 To ComboBox1.Items.Count
If ComboBox1.Items(i) = line Then
IndexFound = i
Exit For
End If
Next
---------
Code
---------

Can anyone help me please,

Thanx
Jul 17 '05 #1
3 6664
I'll bet the program does not hang
- it should come up with a ruddy great Error Message

For i = 0 To ComboBox1.Items.Count - 1

Note the minus one
- Zero Based arrays are a PITA
On 10 May 2004 03:50:30 -0700, ni****@hollandridderkerk.nl (Niels)
wrote:
Hello,
I'm trying to get te index of a specific text in a ComboBox.
The ComboBox is filled by searching for filenames in a directory.
The text of the last item selected in the ComboBox is saved in a
textfile in the OnExit Event of the Mainform.
While loading the Mainform I want the text that was saved in the file
to be compared with the items in the ComboBox ad get the index of the
found item, so that I can set it as selected.

I thought i could do it something like this, but the program hangs
before I can see anything.
---------
Code
---------
Dim i, As Integer
Dim line As String
For i = 0 To ComboBox1.Items.Count
If ComboBox1.Items(i) = line Then
IndexFound = i
Exit For
End If
Next
---------
Code
---------

Can anyone help me please,

Thanx


Jul 17 '05 #2
The easiest way, if there can be only one match, is by using the
CB_FINDSTRING or CB_FINDSTRINGEXACT messages ...

sItemToFind = "Hello World"

matchIndex = SendMessage(combo1.hwnd, CB_FINDSTRINGEXACT, -1, ByVal
sItemToFind)

if matchIndex >-1 then msgbox "the item is index " & matchIndex
CB_FINDSTRINGEXACT (or LB_* for list boxes) does just that ... if the combo
entry was "Hello World here I come" CB_FINDSTRINGEXACT would fail above.
CB_FINDSTRING on the other hand would locate the item. Note however if the
item was "I'd like to say Hello World", neither messages would find the item
since the item does not begin with the words "Hello World".
--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Niels" <ni****@hollandridderkerk.nl> wrote in message
news:b1*************************@posting.google.co m...
: Hello,
: I'm trying to get te index of a specific text in a ComboBox.
: The ComboBox is filled by searching for filenames in a directory.
: The text of the last item selected in the ComboBox is saved in a
: textfile in the OnExit Event of the Mainform.
: While loading the Mainform I want the text that was saved in the file
: to be compared with the items in the ComboBox ad get the index of the
: found item, so that I can set it as selected.
:
: I thought i could do it something like this, but the program hangs
: before I can see anything.
: ---------
: Code
: ---------
: Dim i, As Integer
: Dim line As String
: For i = 0 To ComboBox1.Items.Count
: If ComboBox1.Items(i) = line Then
: IndexFound = i
: Exit For
: End If
: Next
: ---------
: Code
: ---------
:
: Can anyone help me please,
:
: Thanx

Jul 17 '05 #3
I've just upgraded 90% of my stuff to VB.NET.. if you hate 0 based array's
steer clear... EVERY array is 0 based in .NET :((

"J French" <er*****@nowhere.com> wrote in message
news:40***************@news.btclick.com...
I'll bet the program does not hang
- it should come up with a ruddy great Error Message

For i = 0 To ComboBox1.Items.Count - 1

Note the minus one
- Zero Based arrays are a PITA
On 10 May 2004 03:50:30 -0700, ni****@hollandridderkerk.nl (Niels)
wrote:
Hello,
I'm trying to get te index of a specific text in a ComboBox.
The ComboBox is filled by searching for filenames in a directory.
The text of the last item selected in the ComboBox is saved in a
textfile in the OnExit Event of the Mainform.
While loading the Mainform I want the text that was saved in the file
to be compared with the items in the ComboBox ad get the index of the
found item, so that I can set it as selected.

I thought i could do it something like this, but the program hangs
before I can see anything.
---------
Code
---------
Dim i, As Integer
Dim line As String
For i = 0 To ComboBox1.Items.Count
If ComboBox1.Items(i) = line Then
IndexFound = i
Exit For
End If
Next
---------
Code
---------

Can anyone help me please,

Thanx

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: thomaz | last post by:
I use the DataSource like below to fill a Combobox: comboBox1.DataSource = dataSet1.Tables; comboBox1.DisplayMember = "ProductName"; When the user types any keyboard key i use the DROPDOWN...
1
by: MrNobody | last post by:
I seem to be having trouble trying to select the right value in a ComboBox DataSourced by a DataTable with a value for a DataRow... For example... In a Windows Form, I have a ComboBox: ...
3
by: Mark P | last post by:
How to solve this? 1. Place a ComboBox in a form 2. On the ComboBox Properties window change the Items to hold: a b c d
5
by: Niels | last post by:
Hello, I'm trying to get te index of a specific text in a ComboBox. The ComboBox is filled by searching for filenames in a directory. The text of the last item selected in the ComboBox is saved...
4
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Hi... Say i have this string call "data" in Form1, this string contains number "5" value.... how do i pass this string to the Form2 and compare with the combo box items... The combo box ...
4
by: Vish | last post by:
Hi, I need to make the text on a combobox that is disabled to be drawn with a black color. I was not able to find any help on this online. The drawItem seems to apply only for the dropdpwn...
5
by: Edd E | last post by:
Hi, I have a database to store my analyses (Access 2002, WinXp), the basic structure is: TABLE 1 = Sample Info TABLE 2 = Analysis type 1 TABLE 3 = Analysis type 2 TABLE 4 = Analysis type 3 ...
3
by: gmazza via AccessMonster.com | last post by:
Hi there, I am trying to run a report using a parameter for where the user chooses a month from a combo box. Then on the report, I want it to compare the month to a date field and choose only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.