rjwebgraphix
Well-known Member
- Joined
- May 25, 2010
- Messages
- 590
I'm trying to read 5 specific lines of a file and put them into a 5 different variables. The first one gets the correct line, but the other 4 are getting data that are not the lines I'm trying to read.
Data for Line 20 returns line 20
Data for Line 21 returns line 23
Data for Line 23 returns line 27
Data for Line 26 returns line 32 (beyond the for i limitations)
Data for Line 27 returns line 35 (beyond the for i limitations)
I added a row count just to double check the i count to the row and it returns the same row and i for each line even though the line it's reading is off. This is one of those files that if you open it in notepad it looks all jacked up, but if you open it in a good editor like notepad++ it looks correct, so I'm not sure if there's something in it that is throwing it off. The file is written out by another program and I have no control in how it is written, so it does need to be worked with as it is.
I will need to trim it also for the actual data within each line that needs to be in the variable, but I haven't done that yet. Maybe there's a better way to do it or maybe the file doesn't read the same. It is a config file, so maybe there is a better way of obtaining the needed information from the file.
Where I'm using a for loop in this case, I originally had it as a Do until end of file. and had the same result. I only changed it to a for loop after a msgbox had me stuck for a bit and wanted to cut down on msgbox in loop issues on a file 400+ lines long.
As always, any help is greatly appreciated.
Text File to be read
https://drive.google.com/open?id=0B8_pR8z6W9n8WmJSQmViX2xQZHc
Data for Line 20 returns line 20
Data for Line 21 returns line 23
Data for Line 23 returns line 27
Data for Line 26 returns line 32 (beyond the for i limitations)
Data for Line 27 returns line 35 (beyond the for i limitations)
I added a row count just to double check the i count to the row and it returns the same row and i for each line even though the line it's reading is off. This is one of those files that if you open it in notepad it looks all jacked up, but if you open it in a good editor like notepad++ it looks correct, so I'm not sure if there's something in it that is throwing it off. The file is written out by another program and I have no control in how it is written, so it does need to be worked with as it is.
I will need to trim it also for the actual data within each line that needs to be in the variable, but I haven't done that yet. Maybe there's a better way to do it or maybe the file doesn't read the same. It is a config file, so maybe there is a better way of obtaining the needed information from the file.
Where I'm using a for loop in this case, I originally had it as a Do until end of file. and had the same result. I only changed it to a for loop after a msgbox had me stuck for a bit and wanted to cut down on msgbox in loop issues on a file 400+ lines long.
As always, any help is greatly appreciated.
Text File to be read
https://drive.google.com/open?id=0B8_pR8z6W9n8WmJSQmViX2xQZHc
Code:
Dim ObjFSO
Dim ObjFile
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFile = ObjFSO.OpenTextFile ("E:\BMX\1MGSV\SteamReg\localconfig.vdf", 1)
Dim User1
Dim User2
Dim User3
Dim User4
Dim StmID
Dim Row
row = 1
for i = 1 to 30
If i = 20 then
User1 = ObjFile.Readline
Msgbox "Hit Row 20 Username1: " & User1 & " " & i & " " & row
ObjFile.SkipLine
End If
If i = 21 then
StmID = ObjFile.Readline
Msgbox "Hit Row 21 ID: " & StmID & " " & i & " " & row
ObjFile.SkipLine
End If
If i = 23 then
User2 = ObjFile.Readline
Msgbox "Hit Row 23 Username2: " & User2 & " " & i & " " & row
ObjFile.SkipLine
End If
If i = 26 then
User3 = ObjFile.Readline
Msgbox "Hit Row 26 Username3: " & User3 & " " & i & " " & row
ObjFile.SkipLine
End If
If i = 27 then
User4 = ObjFile.Readline
Msgbox "Hit Row 27 Username4: " & User4 & " " & i & " " & row
ObjFile.SkipLine
End If
If i <> 20 or i <> 21 or i <> 23 or i <> 26 or i <> 27 then
ObjFile.SkipLine
End If
row = row + 1
next
ObjFile.Close
msgbox "Username1:" & User1 & " " & vbNewLine & _
"Username2:" & User2 & " " & vbNewLine & _
"Username3:" & User3 & " " & vbNewLine & _
"Username4:" & User4 & " " & vbNewLine & _
"StmID:" & StmID