How to Read Database Fields Into and Out of a List BoxLast reviewed: June 21, 1995Article ID: Q112195 |
The information in this article applies to:
- Professional Edition of Microsoft Visual Basic for Windows, version 3.0
SUMMARYThe list box that comes with Visual Basic is not bound, but you can simulate a bound list box in a Visual Basic program. Visual Basic can read records from a database placing the values from each individual field within the record into columns in a list box, which can then be extracted by the Visual Basic program.
MORE INFORMATIONBy reading each field into the list box and separating each field from the next with a TAB character, you can create the illusion of columns. NOTE: By using the SendMessage Windows API function and the LB_SETTABSTOPS constant, you can set the size of your tab stops within your listbox to create custom spacing between fields. Here's an example:
List1.AddItem Data1.Recordset(Field1) & Chr$(9) & Data1.Recordset(Field2)This makes two columns in the list box. Field1 is separated from Field2 by the TAB character. You can use the TAB character to parse the columns back into separate fields. For example:
Dim X As Integer X = InStr(List1.Text, Chr$(9)) Text1 = Mid$(List1.Text, 1, X - 1) ' Will Contain Field1 Text2 = Mid$(List1.Text, X + 1, (Len(List1.Text) - X)) ' Contains Field2For more information, please see the following article in the Microsoft Knowledge Base: ARTICLE-ID: Q71067 TITLE : How to Set Tab Stops in a List Box in Visual Basic Step-by-Step Example
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |