jfergy
asked on
Skipping First line in readline + Loop
In the first file i have a loop where i believe I can do object.readline again to skip the first line? In the second file I have a Read function and not sure if i can do a ignore first line on the Ubound or do it on the setup of the onject?
Thanks for the help.
Thanks for the help.
First Loop Question
---------------------------
' open data file
wscript.echo " Importing """ & sFileName & """ to """ & sTableName & """..."
set oFile = oFSO.OpenTextFile(sFileName, 1, false)
' loop through file
while not oFile.AtEndOfStream
sLine = oFile.ReadLine
wscript.echo Left(sLine, 750)
aLine = Split(sLine, Chr(9))
oConn.execute "INSERT INTO [dbo].[" & sTableName & "](Col0, Col1, Col2, Col3) values(" & SQLString(aLine(0)) & ", " & SQLString(aLine(1)) & ", " & SQLString(aLine(2)) & ", " & SQLString(aLine(3)) & ")"
wend
--------------------------------
Second loop Question
------------------------------
' loop through data file
wscript.echo " reading file..."
sDataFileLines = objDataFile.Read(70000000)
wscript.echo " breaking into lines..."
aDataFileLines = Split(Replace(Replace(sDataFileLines, Chr(0), " "), Chr(13), ""), Chr(10))
for nDataFileLine = 0 to UBound(aDataFileLines) - 1
' get line of data from data file
sDataLine = aDataFileLines(nDataFileLine)
aDataLine = Split(sDataLine, Chr(9))
' build insert statement
sValueList = ""
for a = 0 to UBound(aMapFile)
if Len(aMapFile(a)) then
sFieldName = aMapFile(a)
sValueList = sValueList & ", " & SQLString(aDataLine(a))
end if
next
sInsertStatement = "INSERT " & sTableName & "(" & sFieldNameList & ") VALUES(" & Mid(sValueList , 3) & ")"
' execute insert statement
objConn.execute sInsertStatement
next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For the second loop, simply do this:
For nDataFileLine = 0 to UBound(aDataFileLines) - 1
If nDataFileLine > 0 Then '<-- this is the first line since array is zero-based
'<YOUR CODE>...
End If
Next
For nDataFileLine = 0 to UBound(aDataFileLines) - 1
If nDataFileLine > 0 Then '<-- this is the first line since array is zero-based
'<YOUR CODE>...
End If
Next
ASKER