Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving inormation from a List Box

Status
Not open for further replies.

xbx

Programmer
Dec 15, 1999
2
US
I'm new to Visual Basic 3, and I'm working on a program that saves user input, and some information ends up in a list box. I save the text box info with Type...End Type, but I don't know how to save the list box information. <br>
Any help or advice would be appreciated. :)<br>
<br>
Here's an example of what I have so far: <br>
<br>
(general)<br>
Type Info<br>
<br>
Character As String<br>
Race As String<br>
Class As String<br>
Level As Integer<br>
<br>
End Type<br>
<br>
Sub xSave_Click ()<br>
<br>
Cmdialog1.Action = 2<br>
<br>
Dim File As Info<br>
<br>
File.Character = Character.Text<br>
File.Race = Race.Text<br>
File.Class = Class.Text<br>
File.Level = Level.Caption<br>
<br>
<br>
Open Cmdialog1.Filename For Random As #1<br>
Put #1, 1, File <br>
Close #1 <br>
<br>
End Sub<br>
<br>
Sub xOpen_Click () <br>
<br>
Cmdialog1.Action = 1<br>
Dim File As Info<br>
<br>
Open Cmdialog1.Filename For Random As #1<br>
Get #1, 1, File <br>
Close #1 <br>
<br>
Character.Text = File.Character<br>
Race.Text = File.Race<br>
Class.Text = File.Class<br>
Level.Caption = File.Level<br>
<br>
End Sub<br>
<br>

 
If you need to save all the data in the list box, you will need to loop through the data in the list box saving the data as you go. For example:<br>
<br>
Dim strListData() as String<br>
Dim intListCounter as Integer<br>
<br>
ReDim strListData((ListBox.ListCount -1))<br>
<br>
For intListCounter = 0 to (ListBox.ListCount -1)<br>
strListData(intListCounter) = ListBox.List(intListCounter)<br>
Next intListCounter<br>
<br>
If you know specifically where in the list the information is, try this:<br>
<br>
Dim strListData as String<br>
<br>
strListData = ListBox.List(&lt;position in list&gt;)<br>
<br>
Remember List Box contain an array of data with the starting index of 0 (Zero Based Array). The ListCount property will always be one more than the last array index because of this.<br>
<br>
Hope this points you in the right direction... <p>Bruce Voelp<br><a href=mailto:bvoelp@if.rmci.net>bvoelp@if.rmci.net</a><br><a href= > </a><br>Earn AS in 1976 and BS in 1986. Learn to talk with computers when the only interface was 80 column punch cards, and paper tape.
 
Just thought of something else that might help. If the user is selecting the item from a listbox then all you need to do to get the response is use the ListBox text property.<br>
<br>
strListData = ListBox.Text<br>
<br>
This will return the current selected item in the listbox. <p>Bruce Voelp<br><a href=mailto:bvoelp@if.rmci.net>bvoelp@if.rmci.net</a><br><a href= > </a><br>Earn AS in 1976 and BS in 1986. Learn to talk with computers when the only interface was 80 column punch cards, and paper tape.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top