help with reading commands from a file

Results 1 to 2 of 2

Thread: help with reading commands from a file

  1. #1
    Join Date
    Dec 1969

    Default help with reading commands from a file

    Hi-<BR><BR>I&#039;m writing a parser for an ASCII format that we use here and I am having a real hard time.<BR><BR>I need to read several files into memory, then assemble them and spit out a new file. right now the part that I am having a hard time with is reading certain lines into certain array dimensions/indices<BR><BR>OK, so let&#039;s say I want to read a file until I hit the word &#039;node&#039; when I hit node, I want to store it into a variable (easy, done) then I want to read all the lines following it into an array, each line in it&#039;s own index until I hot a command called &#039;move&#039;<BR><BR>this is what I can&#039;t get to work. Here is what I have tried so far:<BR>&#039;-------------------------------------------------------------<BR> Do While oF.AtEndOfStream &#060;&#062; True &#039; start at the top, 1 line at a time<BR> sLine = oF.ReadLine()<BR> sLine = Replace(sLine, Chr(9), "") &#039; remove tabs<BR> <BR> If sLine &#060;&#062; "" and left(sLine, 1) &#060;&#062; "/" Then<BR> If Left(sLine, 4) = "node" Then<BR> Do<BR> sLine = oF.ReadLine()<BR> MsgBox(sLine)<BR> loop Until Left(sLine, 4) = "move"<BR> End if<BR> End if<BR><BR>....&#060;snip&#062;<BR>&#039;--------------------------------------------------------------<BR><BR>I&#039;m still getting the "move" command spit out. ARGHH!!<BR><BR>any ideas of a better way to do this?<BR><BR>Thanks-<BR><BR>Steve

  2. #2
    Join Date
    Dec 1969

    Default Well, you can't find what's in...

    ...a line until after you&#039;ve read it.<BR><BR>So OF COURSE you are spitting out the "move" line before you discover you&#039;ve reached it.<BR><BR>Heck, your code *insists* on that happening:<BR><BR> sLine = oF.ReadLine( )<BR> MsgBox( sLine )<BR><BR>[Though how you get MsgBox to work with ASP is a mystery to me.]<BR><BR>You are *ALWAYS* spitting out the line as soon as you read it. Before you ever check its contents. So why are you surprised???<BR><BR>And can I ask a silly question? Why do you first check to see if the line is blank or if it starts with a / ??? If the first 4 characters of the line are "node" than how the hell *could* it be blank or start with a slash???<BR><BR>How about this:<BR><BR> If Left(sLine, 4) = "node" Then<BR> sLine = oF.ReadLine()<BR> Do Until Left(sLine,4) = "move"<BR> MsgBox(sLine)<BR> sLine = oF.ReadLine()<BR> Loop<BR> .... process "move" stuff ...<BR> End If<BR><BR>Alternatively:<BR><BR> If Left(sLine, 4) = "node" Then<BR> Do <BR> sLine = oF.ReadLine()<BR> If Left(sLine,4) = "move" Then Exit Do<BR> MsgBox(sLine)<BR> Loop<BR> .... process "move" stuff ...<BR> End If<BR><BR>And various other ways.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts