Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21843

Load a listbox from a textfile?

$
0
0
Hi there! I am working on a school program that will randomly pick a student to ask a question. I have a listbox called StudentList, and I am borrowing code from an older project that loaded a textfile to a bunch of label captions, but for the purpose of this prog I am using a listbox to store the names.

This was the old code

VB Code:
  1. ' THIS CODE LOADS The Students Names TO the Label Captions
  2.     Dim sFileText As String
  3.         Dim iFileNo As Integer
  4.         Dim iCount As Integer
  5.           iFileNo = FreeFile
  6.               'open the file for reading
  7.              
  8.           Open App.Path & "\StudentRosters\Roster1\Roster1.txt" For Input As #iFileNo
  9.         'change this filename to an existing file!  (or run the example below first)
  10.               'read the file until we reach the end
  11.           Do While Not EOF(iFileNo)
  12.            iCount = iCount + 1
  13.              StudentNum.Text = iCount
  14.             Input #iFileNo, sFileText
  15.               'show the text (you will probably want to replace this line as appropriate to your program!)
  16.             Attendance.StudentNameLBL(iCount).Caption = sFileText
  17.           Loop
  18.               'close the file (if you dont do this, you wont be able to open it again!)
  19.           Close #iFileNo

I still would like to keep the number of students in the iCount, but I can always do Studentlist.listcount, but how do I chance Attendance.StudentNameLBL(iCount).Caption to StudentList.additem so the textfile loads there? Thanks for your help!!

Viewing all articles
Browse latest Browse all 21843

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>