none
Simple text file read error RRS feed

  • Question

  • I have a very small program that reads a text file. I want to read it and assign an array item to each line.
    But when it get to line 7 or 8 it aborts and the screen closes before I can read it. I am guessing there may
    be some bad char.'s in the file, that's my best guess. Here's the code -

    Sub PAUSE
    TextWindow.Write("Pause - ")
    Disp = TextWindow.Read() 
      EndSub

    TextWindow.Write("Convert Up To 10,000 Records !")
    TextWindow.WriteLine( " " )
    num = 9999

    READ:
    For N=1 To num
      in1 = File.ReadLine("C:\temp\laspicecal.txt",N)
          var1 [N]     = in1                  
          varLen       = Text.GetLength(var1 [N])    
          varSubStr1   = Text.GetSubText(var1 [N],2,9)
          in2 = varSubStr1
          R = R + 1  
      If in2 = "***EOF***" THEN
                           Goto EOF
                         Else
                            A [N] = text.ConvertToUpperCase(in1)
                           ' A [N] = in1
                           TextWindow.WriteLine( A [N] )
                           ' PAUSE()
    ENDIF
    ENDFOR

    EOF:
    R = R - 1
    TextWindow.WriteLine( R + " Records Read!" )
    TextWindow.WriteLine( " " )


    ( I Don't know of a way to provide the text file input, but if I have a line with "P" in it, it's OK,
      But, if it reads "Pa" or any other Char. beside the the "P" and it aborts!
      It is some sort on "Unhandled Exception:" error, it flash's by too quick. )
    • Edited by LaLag Tuesday, August 18, 2009 3:01 AM
    Tuesday, August 18, 2009 1:15 AM

Answers

  • It was the

    varSubStr1 = Text.GetSubText(var1 [N],2,9)

    Line causing the problem, I fixed it with a length check!
    • Marked as answer by LaLag Tuesday, August 18, 2009 3:17 AM
    Tuesday, August 18, 2009 3:17 AM

All replies

  • It was the

    varSubStr1 = Text.GetSubText(var1 [N],2,9)

    Line causing the problem, I fixed it with a length check!
    • Marked as answer by LaLag Tuesday, August 18, 2009 3:17 AM
    Tuesday, August 18, 2009 3:17 AM
  • wow some one that reads in a data line and does something. been looking for u. where do you point to the output file?

    all i want to do (to start is read a RECORD and then write it out to another file.

       in1 = File.ReadLine("C:\temp\laspicecal.txt",N)

    is input where do u define the output file?

    (this is how i learned fortran, pl/1, cobol and sas and basic 40 years ago)

    tks greg rudowsky xenduro@bigfoot.com

    Tuesday, December 1, 2009 9:48 AM