May 23, 2019, 07:02:06 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Text file question

Started by Haim, November 19, 2007, 05:29:48 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Haim

Hello,
I have a text file with strings that may be longer than 255 characters.
How can I read the file?
Readstring with maxbytes >255 crashes!

Help please

Haim

Barney

This is taken from the help file:

STRING - A string of characters up to a length of 255
DSTRING - A dimensionable string that can contain any number of characters.
WSTRING - A unicode string up to a lnegth of 255 characters.
DWSTRING - A dimensionable unicode string that can contain any number of characters.

Barney

Haim

Barney,
I tried Dstring dimensioned to more than 255, but it crashed

Haim

peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

John S

Haim,
Below is some code I have used to read a text file into my program:

Code Select

TabDlg::LoadHelpText()
{
dstring helptext[6595];
unsigned int hFile = OpenFile(GetStartPath()+"HelpText.txt", MODE_READ);
if(hFile)
{
Read( hFile, helptext, len(byte)*6595 );
m_help_txt->SetText( helptext );
}
return true;
}
John Siino, Advanced Engineering Services and Software

Haim

November 19, 2007, 11:14:43 am #5 Last Edit: November 19, 2007, 11:23:16 am by Haim
Hello,
Thank you all for your responses.
I was trying to read a text file with lines of varying length, so I had to use somethig like readstring() and not read() which requires a size parameter.

I am still puzzling over it... :-[

Just fixed it but I do not understand why.

This crashed the program:

uint hfile=openfile("C:\program files\aurora\examples\ur\ITD UR OCTOBER 2007.csv",mode_read);
dstring s[300];
if hfile
{
   readstring(hfile,s,280);
   print(s);
closefile(hfile);
}

I fixed it by chnging
dstring s[300] to dstring s[500];

Why does this work???