Solved

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

Posted on 2007-04-09
5
289 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

11 Experts available now in Live!

Get 1:1 Help Now