Converting listbox items to a string.

  • Thread starter Thread starter jazFunk
  • Start date Start date
  • Tags Tags
    String
AI Thread Summary
The discussion revolves around the challenge of converting items from a ListBox to a single string in VB (Visual Basic). The original poster struggles with the task, initially attempting to use the ListBox's items but encountering errors. A suggestion is made to use the syntax Str(List1.List(x)), but this does not resolve the issue. The poster also tries to convert the items using the ToString method, which fails to concatenate the items into one string. A working solution is eventually provided, where a loop is used to concatenate the items from the ListBox into a single string, successfully achieving the desired outcome. This method involves iterating through the ListBox items and appending them to a label's caption.
jazFunk
Messages
12
Reaction score
0
It seems like it would be a fairly simple task, yet I have been unable to complete this task.
 
Technology news on Phys.org
jazFunk said:
It seems like it would be a fairly simple task, yet I have been unable to complete this task.

what language are you using?
 
I'm using VB.
 
try with Str(List1.List(x))
where x = the item # you want. Remember it starts from 0
 
That didn't work either. The error was that 'List is not a member of the 'Systems.Windows.Forms.ListBox'.

I try this with no error but it's not converting the items to a single string:

Dim OrigString As String = Me.lstLegend.Items.ToString()

Essentially I need to convert all of the items in a list box to a single string which can then be processed through a function.

Thanks, in advance.
 
Private Sub Command1_Click()

For x = 0 To 2
Label1.Caption = Label1.Caption & CStr(List1.List(x))
Next x

End Sub

That worked perfectly for me, try it. I had 3 items in my List.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top