[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2007-04-09
5
Medium Priority
?
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 1600 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 400 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 1600 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

650 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