Ariane Soft PPL2 Pocket Programming DataMite
  #1  
Old 01-12-2007, 01:54 AM
plinydogg plinydogg is offline
Senior Member
 
Join Date: Sep 2006
Posts: 119
Default Reading a Text File into an Edit Control

I'm trying to load some text into a text file and I used the following code:

textFile$ = FOpen ({test.txt}, "r"
firstline$ = ReadString (textFile$);
Edit_Set(EDIT103$, firstline$);

It didn't work (and I got an access violation). I'm sure I'm not even using these properly. Is there a PPL file somewhere that uses these commands so I can use it as a model? Or do I need to hunt for some C examples on the Internet?

Thanks, as always!
Reply With Quote
  #2  
Old 01-12-2007, 03:12 AM
plinydogg plinydogg is offline
Senior Member
 
Join Date: Sep 2006
Posts: 119
Default

Oops. I completely missed the part in the help file that addresses these commands. Sorry. I'll post back if I can't figure it out after reading them. Sorry to waste everyone's time.
Reply With Quote
  #3  
Old 01-12-2007, 09:13 PM
plinydogg plinydogg is offline
Senior Member
 
Join Date: Sep 2006
Posts: 119
Default

Does anyone remember how to specify a carriage return? What I'm trying to do is read several lines of a textfile. I can read one line but don't know how to read the next. Thanks!
Reply With Quote
  #4  
Old 01-12-2007, 09:20 PM
matteo.m matteo.m is offline
Senior Member
 
Join Date: Jun 2006
Location: Turin
Posts: 372
Default

it should be \r or chr$(13) may be you need also a \n for newline aka chr$(10)
Reply With Quote
  #5  
Old 01-12-2007, 09:46 PM
PointOfLight PointOfLight is offline
Senior Member
 
Join Date: Sep 2006
Posts: 1,197
Default

Are you trying to read the whole file into the edit control or just part of it? If you want to read the whole file, simply use the command Edit_LoadFromFile(Edit$, FileName$). Now let's say you just wanted to read the first 10 lines. You could do something like this:

Code:
fp$ = fopen("filename", "r");
x$ = 0;
data$ = "";
while((x$ < 10) and (not(feof(fp$))))
  line$ = ReadString(fp$);
  data$ = data$ + line$ + "\n";
  x$++;
end;
fclose(fp$);
Edit_Set(Edit$, data$);
[Edit]
Forgot to mention that if you haven't already, make sure the ES_MULTILINE property is set.
Reply With Quote
  #6  
Old 01-12-2007, 09:52 PM
plinydogg plinydogg is offline
Senior Member
 
Join Date: Sep 2006
Posts: 119
Default

Thanks matteo.m and PointOfLight! I will try it right away! And as always, thanks VERY much!
Reply With Quote
  #7  
Old 01-12-2007, 10:05 PM
plinydogg plinydogg is offline
Senior Member
 
Join Date: Sep 2006
Posts: 119
Default

POL: What does x$ <; 10 mean? Specifically, why the semicolon?
Reply With Quote
  #8  
Old 01-12-2007, 10:28 PM
PointOfLight PointOfLight is offline
Senior Member
 
Join Date: Sep 2006
Posts: 1,197
Default

Sorry, that was supposed to be "less than or equal". For some reason when you put an = next to a < it translates the = as a ;.
Reply With Quote
  #9  
Old 09-14-2008, 06:18 AM
Alain Carignan Alain Carignan is offline
Junior Member
 
Join Date: Apr 2008
Posts: 19
Default

The order Edit_Loadfromfile (edit$, filemname$) does not seem to function. Here two lines simple to replace the code of the procedure.
proc Edit_LoadFromFile (edit$, Filename$)
local (s$, i$, slist$);
s$ = LoadStr (Filename$, i$);
settext (edit$, s$);
end;
In the same idea have can replace the procedure Edit_SaveToFile (edit$, Filename$), even if this one functions well with l' origin.
proc Edit_SaveToFile (edit$, Filename$)
local (lst$, savetext$);
savetext$=gettext (edit$);
savestr (fn$, savetext$, length (savetext$));
end;
I ask for myself why the original orders places by lists?

Last edited by Alain Carignan; 09-14-2008 at 06:20 AM.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) ArianeSoft Inc.
Copyright © 2009 www.ppl-lang.com - All rights reserved
Web Design by BR Web Consulting Ltd