English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to save and load a list in Visual Basic.
This is the code I have so far

http://www.piratetech.org/temp/code.rtf

2007-05-06 07:34:16 · 3 answers · asked by Charles X 3 in Computers & Internet Programming & Design

3 answers

I suggest that you become familiar with Collections....

The Listbox is a collection of Items which will be displayed.

The collection which holds this list is access via the ITEMS property of the ListBox (ListBox1.Items) . Your code is adding items to this collection using the add method

ListBox1.Items.Add (yourItem as String)

Each Item which is added is identified within the collection by a unique index. This is similar to the index of an array like myArray(index).

The way you are adding items to your list box is not a problem (so far) in your code. Your issue is in the save procedure you have written.

Your Code is :
myStreamWriter.WriteLine(ListBox1.Items)
This identifies the listbox collection object and not an individual item. You will need to modify your code to identify a specific string contained in the collection by using the ITEM property and an index value.

myStreamWriter.WriteLine(ListBox1.Items.Item(index))

I have placed an integer variable called index which is initialized to zero and is incremented each time the listbox item is saved to the file.
You will have to limit your index value to be less than the Items.Count otherwise you will throw an exception.

2007-05-06 10:03:39 · answer #1 · answered by MarkG 7 · 0 0

decision convey private Sub Command1_Click() ' call the shop record habitual call SaveList end Sub private Sub Form_Load() Dim intCtr As Integer ' Populate the listbox with try ' information For intCtr = 0 to ten With List1 .AddItem "merchandise " & intCtr end With next intCtr end Sub private Sub SaveList() Dim iHandle As Integer ' look after to the subsequent available document Dim iCtr As Integer ' Loop Counter ' get the subsequent available document iHandle = FreeFile() ' Open the document for output. ' be conscious that if the document does no longer exist then it is going to ' be created immediately Open "C:record Contents.txt" For Output As iHandle For iCtr = 0 To List1.ListCount ' Iterate over each and each merchandise interior the record ' and write the fee to the document Print #iHandle, List1.record(iCtr) next iCtr close iHandle end Sub

2016-10-30 12:03:27 · answer #2 · answered by staves 4 · 0 0

'//An internal way is by having a richtextbox.
private sub click(blah blah) handles clack.click
listbox.items.add(richtextbox1 _
.text.toarray)
end sub

2007-05-06 08:06:38 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers