We help IT Professionals succeed at work.

Skipping First line in readline + Loop

jfergy
jfergy asked
on
911 Views
Last Modified: 2008-02-01
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.
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

Open in new window

Comment
Watch Question

IT Director
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
What would you recommend on the second?
jkaiosIT Director

Commented:
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
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.