Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » General Visual Basic » Listbox to textbox


Listbox to textboxExpand / Collapse
Author
Message
Posted 3/27/2012 12:26:00 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/4/2012 11:43:55 PM
Posts: 4, Visits: 7
I'm new to VB and new to this forum. Anyway I am wondering how you would be able to change the text of a textbox with each click of a button. I understand that using an array would probably be best, but for the sake of practice etc. I am trying to do it so that each line of text would be pulled from a list stored in a listbox. I'm assuming listbox.items.count and listbox.items(n) would be used and then you would set n+=1 or something along these lines but I can't get anything to work beyond displaying the first line of the listbox.
Post #31327
Posted 3/28/2012 12:56:09 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/4/2012 11:43:55 PM
Posts: 4, Visits: 7
Alright then. I guess this question is unanswerable.
Post #31330
Posted 4/2/2012 6:13:54 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 10/18/2012 11:40:00 AM
Posts: 548, Visits: 2,556
Sure there is but I wouldn't use a CommandButton. Here's a simple example using the ListBox Click() event. Any list item clicked will be put on a new line in the textbox.

' To put each list item on its own textbox line you must first set its Multiline property to
' True at designe time in the Properties window.

Option Explicit
Dim strTxt As String
Dim i As Integer

Private Sub Form_Load()
   strTxt = "Item"
   Text1.Text = ""    ' clear the textbox
   For i = 1 To 10
      List1.AddItem strTxt & " " & i
   Next i
End Sub

Private Sub List1_Click()
   Text1.Text = Text1.Text & List1.Text & vbNewLine
End Sub



________________________________________________________________ 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

Mark's Syntax.Zip    Pause Sub

I don't answer programming questions via PMs. That's what the forum is for! 

Post #31341
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 12:23am