How do i take the text from a listbox and put it in a textbox?
Printable View
How do i take the text from a listbox and put it in a textbox?
well, if you use the Select Case function, you could say
Like that.Code:Select Case lstWhatever
Case0 "Hi"
txtWhatever.text="Hi"
Case1 "Hello"
txtWhatever.text="Hello"
End Select
What do you want to take from the listbox? All of the listitems or specific listitems?
List1.List(0) is the 1st item, List1.List(1) is 2nd item & so on.
Id like to take all the items LaVolpe if you could help please thanks.
I have tried
But text1 just stays blank.Code:Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount
i = i + 1
Text1.Text = List1.List(i)
Next i
End Sub
Almost. A couple of things
1. The loop variable, i, is automatically incremented in a For:Next loop. Do not increment it yourself.
2. Your textbox must have MultiLine=True to display more than one line. Also when you append text and want a new line, you should use vbNewLine
3. List items are zero-bound, this means you cannot loop to List1.ListCount, must be List1.ListCount-1
Tweaking your loop code only
Code:For i = 0 To List1.ListCount - 1
Text1.Text = Text1.Text & List1.List(i) & vbNewLine
Next i