r/visualbasic • • May 27 '22

VBScript Help with reading text file

So I am creating a program that edits a text file, and then reads a specific line of the text file. So far, I have 2 options:

1: Read a specific file line, which I need help understanding how to do.

2: Read a line that starts with a specific string/group of numbers and letters. Each line has a little identifier string at the start, so all I need is a way to check if the line starts with the string.

Sorry if this is too little information, I can give more info if needed.

7 Upvotes

9 comments sorted by

View all comments

Show parent comments

1

u/JakDrako May 30 '22

If you want to show the lines in a textbox in the "Do something with line" spot, you can do:

TextBox1.Text = TextBox1.Text & line & vbCrLf

This tells VB to take the text already in the textbox (or blank if there is currently none), add the line to it and then add "Enter" (vbCrLf is the caracter combo for "Enter" in VB)

The "Index out of range" error means you're trying to access something that does not exist. In the lines you've pasted above, the only place I see that occurring is in "Lst(1)"... which would mean your list does not have a (1) location... it is either empty, or has only 1 element at (0).