dear all,
i got a problem about the arraylist i want to create and return an arraylist with each student ID for populating listboxes.

Public Function StudentIDs() As ArrayList
    End Function

To display the student ID in the listbox by calling this function. (i need to read student information from text file. there are 6 student, so the result should be 100,101,102,103,104,105). how to do this? thank you very much.

Recommended Answers

All 5 Replies

One method can be:

Create a new empty ArrayList
Open the file with a text reader.
Then read the file one line at time using the readLine method until the end of file.
For each read line( if any ), add the string to the ArrayList.
Finally, close the text reader and return the ArrayList.

If you have some problems coding that, please show us how far you coded and the errors you find.

Hope this helps

thanks, i can do it. now new problem, in list box there are two things(ID name,like: 100 mike), but i just want to use the ID(100).so how to read only the ID from the list box?

If you have a 'blank' (or any oder separator) between te number and the name, you can use the String.Split(" "c) function, from the Selected Item in the list box.

As the selected Item is the type of Object, you will need to convert it to type string, before using the Split.

Split returns an array of strings, not including the separator. If the ID is the first element then select the element 0 of the returned array.

Hope this helps works.thank you very much!

Glad to know.
Please be so kind to mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.