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

Load a textfile so each line of a textfile is loaded to a specific label caption?

$
0
0
Hi there! I am working on a newer version of an attendance program for students to log into when they arrive in the morning. The kids love it, but there have been requests by teachers to allow it to store more than 1 roster of students.

Right now each students name is in its own textfile, such as Student1.txt student2.txt, etc.

What I would like to do is keep all of the students in a specific txt file called Roster1.text. This textfile will keep all of the students for one class in a single file for easier access.

The problem is, I am not sure how to load the textfile so say Line1 of the Roster1.txt would go to a label caption called StudentName1LBL.caption

The label captions are on the screen so the student clicks on them and logon,

The code I use now, loads all of a textfile to a label caption, like this...
VB Code:
  1. ' THIS CODE LOADS STUDENT#30
  2. Dim sFileText As String
  3.     Dim iFileNo As Integer
  4.       iFileNo = FreeFile
  5.           'open the file for reading
  6.       Open App.Path & "\Student30.txt" For Input As #iFileNo
  7.     'change this filename to an existing file!  (or run the example below first)
  8.           'read the file until we reach the end
  9.       Do While Not EOF(iFileNo)
  10.         Input #iFileNo, sFileText
  11.           'show the text (you will probably want to replace this line as appropriate to your program!)
  12.         Attendance.StudentNameLBL30.Caption = sFileText
  13.       Loop
  14.           'close the file (if you dont do this, you wont be able to open it again!)
  15.       Close #iFileNo

I was wondering if anyone would know of a way to alter this code so if I wanted to load student 30, it would load line 30 out of a Roster1.txt file? Thanks so much!

Viewing all articles
Browse latest Browse all 21839

Trending Articles



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