#1 is the file handle that is being used to gain access to the file, not the line number.
I know you solved the issue, just thought you might want an explanation. Sub ImportLineVariables() Dim Raw1$, Raw2$, Raw3$ Open “ServerNamePathtest.txt” For Input As #1 Line Input #1, Raw1 ‘ “IP: ” = 4 characters Raw1 = Right(Raw1, Len(Raw1) – 4) MsgBox Raw1 Line Input #2, Raw2 ‘ “Machine: ” = 9 characters Raw2 = Right(Raw2, Len(Raw2) – 9) MsgBox Raw2 End Sub I can get it to read my first line fine using Line Input, but the sequential lines produce errors. So, anything after the colon-space (“: “) but before the carriage return – char(13) & char(10) – for each line would be my variable (Raw1 = first partial line variable, Raw2 = second partial line variable, etc.). I want to import the “x”s (and periods between them) as separate variables. For example, the text file’s first line might be this: “IP: xx.xxx.xx.xxx,” and the next line might be, “Machine: Xxxxx,” followed by, “Alt IP: xx.xx.xxx.xxx”. While I can read the whole text file, I want to later just be able to read parts of the line as distinct variables. I have an application that creates a text file, which is then saved. if you read line by line and store these lines in a string looking for ips, i recommend you use regular expressions to find these ip addresses.įrom: MrkFrrl via vb-dotnet-l Sent: Monday, J12:33 PM To: Tonci Korsano Subject: How do you read parts of text file line with VB? I would say streamreader is more suitable for small text files, like 64kb or less.
I would recommend using textreader or streamreader classes to read these text files. Open “”ServerNamePathtest.txt”” For Input As #1Īlso, how does the Print command relate to this? I’ve seen it used by someone else but don’t fully understand its function. So, anything after the colon-space (“”: “”) but before the carriage return – char(13) & char(10) – for each line would be my variable (Raw1 = first partial line variable, Raw2 = second partial line variable, etc.). I want to import the “”x””s (and periods between them) as separate variables. For example, the text file’s first line might be this: “”IP: xx.xxx.xx.xxx,”” and the next line might be, “”Machine: Xxxxx,”” followed by, “”Alt IP: xx.xx.xxx.xxx””.