Solved

Getting all data from all items in a VB6 listbox into a string variable

Posted on 2007-04-09
5
292 Views
Last Modified: 2013-12-25
I'm using VB6. How do I get the data from all items in a listbox, whether they are selected or not? I have multi-select set to Extended and I have columns set at 0. This listbox is not bound to anything. I populate it with code using the AddItem method.

For i = 0 to Me.lstStartup.ListCount
     strStartup = strStartup & Me.lstStartup.ListIndex(i)
Next i

The above code doesn't seem to work.
0
Comment
Question by:HKComputer
5 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 400 total points
ID: 18879262
You need to use the 'List' property instead of the ListIndex one. Also you need to go from zero to count-1

You might also want to separate each value with a new-line or a tab?


For i = 0 to Me.lstStartup.ListCount -1
     strStartup = strStartup & Me.lstStartup.List(i)
Next i


0
 
LVL 15

Expert Comment

by:cquinn
ID: 18881385
Listboxes in Access don't have a List property - you need to use Itemdata if referring to the bound column, or the Column property if referring to a different column in a multicolumn listbox

For i = 0 to Me.lstStartup.ListCount -1
     strStartup = strStartup & Me.lstStartup.ItemData(i)  'the bound column
Next i

For i = 0 to Me.lstStartup.ListCount -1
     strStartup = strStartup & Me.lstStartup.Column(i, 4)  'the fourth column
Next i
0
 
LVL 4

Author Comment

by:HKComputer
ID: 18881675
cquinn,

I'm actually using the listbox control in VB6. And the first solution posted is what I needed. I had actually tried to use "List" already but I was referencing the wrong listbox on my form, an empty one, and it appeared that my code wasn't working.

But I am noticing that there are some differences between listboxes in VB6 and Access. I'm more accustomed to using MS Access so the listbox in VB6 has me baffled.

Like, I don't understand VB6's implementation of columns. I'm just separating my "columns" with commas, each text value with a given amount of spaces, placing a comma after each value, and then using a fixed width font in my list box. This way I'm creating my own "columns". Also, I can use arrays to parse the data this way.

But I also wish I could have a scroll bar on the bottom (horizontal) so I could scroll over to see all the data.

I welcome any suggestions.
0
 
LVL 6

Assisted Solution

by:nirojexpert
nirojexpert earned 100 total points
ID: 18913258
use the flex grid. see the semi-pseudo code.
with grid
.rows=0:.cols=0 'clearing the grid
.rows=2:.cols=4 'defining the grid size
'writing headings
.textmatrix(0,0)="SN": .textmatrix(0,1) = "name" .....
'writing data
do while not rs.eof
 .rows=.rows+1 'adding new row for each record from database
.textmatrix(.rows-1, 0) = SN ...........
 rs.moveNext
loop
....
...
end with
0
 
LVL 18

Assisted Solution

by:JR2003
JR2003 earned 400 total points
ID: 18913441
You should probably use a ListView control.
You can set the style to report and it is a control similar to the one on the right hand side of Windows Explorer.  When it is in report mode it is like the details view in windows explorer.  You can also define columns etc..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
consolidate or create a new vba code for performing tasks 5 64
bit defender blocks good applications 2 83
Protecting vb6 & .Net code Obfuscation 18 97
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now