For Programmers: Free Programming Magazines  


Home > Archive > Clarion > October 2006 > Read text file line by line









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Read text file line by line
ronaldve@xs4all.nl

2006-10-30, 9:55 pm

Hi, I'm fairly new with clarion.
What I want is to read an existing text file line by line and put each
line in a variable.
Could someone get me started with this with some sample code?
I've tried several things from the documentation but it just wouldn't
work.

Thanks. Ronald.

Olivier Cretey

2006-10-30, 9:55 pm

Ronald,

Something like what follows should work...
I've declared a 255 char string as the "line" but you can change this to
your taste
Do not forget to add the Ascii driver to your project.

Program
Map
End

AsciiFile File, Driver('ASCII')
Rec Record
Line String(255)
End
End

MyStringVar String(255)

Code
AsciiFile{Prop:Name}='MyAsciiFile.txt'
Open(AsciiFile)
Set(AsciiFile)
Loop
Next(AsciiFile)
If ErrorCode()
Message( ErrorCode() & ' ' & Error()
Break
End
MyStringVar = Clip(AsciiFile.Line)
Message(MyStringVar)
End
Close(AsciiFile)
Message('Done !')

Regards

--
Olivier Cretey
o.cretey@cia-informatique.com
www.clarion.free.fr
Verneuil sur Seine (78), France


ronaldve@xs4all.nl

2006-10-30, 9:55 pm

Thanks!
This works perfect.

Best regards,
Ronald.

Olivier Cretey schreef:

> Ronald,
>
> Something like what follows should work...
> I've declared a 255 char string as the "line" but you can change this to
> your taste
> Do not forget to add the Ascii driver to your project.
>
> Program
> Map
> End
>
> AsciiFile File, Driver('ASCII')
> Rec Record
> Line String(255)
> End
> End
>
> MyStringVar String(255)
>
> Code
> AsciiFile{Prop:Name}='MyAsciiFile.txt'
> Open(AsciiFile)
> Set(AsciiFile)
> Loop
> Next(AsciiFile)
> If ErrorCode()
> Message( ErrorCode() & ' ' & Error()
> Break
> End
> MyStringVar = Clip(AsciiFile.Line)
> Message(MyStringVar)
> End
> Close(AsciiFile)
> Message('Done !')
>
> Regards
>
> --
> Olivier Cretey
> o.cretey@cia-informatique.com
> www.clarion.free.fr
> Verneuil sur Seine (78), France


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com