Solved*reading an rtf file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

Solved*reading an rtf file

Post by JamesWebster » Thu Aug 11, 2011 10:20 pm

Putting this into my card didn't function

Code: Select all

local Intro
On Preopencard
   put "/Tippen/Intro.rtf" into Intro
   disable fld id 1024
   Open file specialFolderPath("desktop") & Intro for read
   read from file specialFolderPath("desktop") & Intro until EOF
   set the rtftext of fld id 1024 to url(specialFolderPath("desktop") & Intro)
   close file specialFolderPath("desktop") & Intro
end Preopencard
While I want the content of the rtf file in the field, the only thing I get is its filepath, any advice?
Last edited by JamesWebster on Sat Aug 13, 2011 8:16 am, edited 1 time in total.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: reading an rtf file

Post by bn » Thu Aug 11, 2011 10:55 pm

Hi James,

welcome to the Forum.

You are actually mixing two ways to read data into your field:
one where you first open the file, then read and close the file. After reading until EOF the data is in the variable it

Code: Select all

On Preopencard
   local Intro -- initialization optional
   put "/Tippen/Intro.rtf" into Intro
   disable fld id 1024
   Open file specialFolderPath("desktop") & Intro for read
   read from file specialFolderPath("desktop") & Intro until EOF
   set the rtftext of fld id 1024 to it
   close file specialFolderPath("desktop") & Intro
end Preopencard
the other URL form is easier/shorter for reading a whole file, here you put it directly into the rtfText of the field

Code: Select all

On Preopencard
    put "/Tippen/Intro.rtf" into Intro
    disable fld id 1024
    set the rtftext of fld id 1024 to url ("file:" & (specialFolderPath("desktop") & Intro))
end Preopencard
both scripts tested and they work.

with the url form it is important to put "url ("file:" & (specialFolderPath("desktop") & Intro))" into parenthesis. Otherwise here wrong: url "file:" & (specialFolderPath("desktop") & Intro) it does not work.

You initialized a script local variable at the top of the script but only used one handler. The script local variable is persistent between calls and accessible to every handler that is below its initialization. Not needed here. If you want to initialize the variable you can do it as I indicated in the first script. Except if you turned on explicit variable in the preferences: then you have to declare the variables. But still in this case no need to declare the variable outside of the handler.



Kind regards

Bernd

JamesWebster
Posts: 25
Joined: Sun Aug 07, 2011 11:36 am

Re: reading an rtf file

Post by JamesWebster » Thu Aug 11, 2011 11:12 pm

thank you very much - I guess I've got a lot to learn going from VB to Livecode

Post Reply