Converting from SuperCard

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm
Location: City of God Lug

Converting from SuperCard

Post by LittleGreyMan » Sat Jun 16, 2012 8:55 pm

Hi,

I am testing LiveCode 5.5 on Mac OS 10.7.4 and am experimenting some problems with a simple project.

Scripts have been pasted from SC 4.63 into the buttons of the LiveCode stack and modified to match LiveCode syntax. Obviously, the translation is not perfect…

One card, with 2 fields containing accounting data, 2 buttons (Import and Convert). The purpose is to convert a file to match the requirements of my accountant.

The first field (ListeFournisseurs) contains the list of the providers names and codes:

08000001,SNCF
08000002,Restaurant
08000003,Autres fournisseurs
08000004,Decitre
08000005,Leclerc
08000006,Orange
etc.

The second field (ListeOperations) is populated by data using the first button, Import, which works fine. I cannot post a sample of this data here, as it is confidential.

Here is the script of the Convert button, which is supposed to replace some char strings by the provider name when its code is detected at the beginning of a line (in this line and the following lines) :

Code: Select all

on mouseUp
   global gFichier
   lock screen
   put the text of fld "ListeOperations" into tListe
   repeat with i = 1 to the number of lines in tListe
      if char 2 to 3 of line i of tListe = "08" then
         put char 2 to 9 of line i of tListe into tCode
         find word tCode in fld "ListeFournisseurs"
         put the foundLine into tLigne
         select before fld "ListeFournisseurs"
         if tLigne is not empty then
            do "put item 2 of" && tLigne && "into tFournisseur"
            if length (tFournisseur) > 20 then
               put char 1 to 20 of tFournisseur into tFournisseur
            else
               repeat while length (tFournisseur) < 20 
                  put space after tFournisseur
               end repeat
            end if
            put char 22 to 41 of line i of tListe into tLibelle
            put tFournisseur into char 22 to 41 of line i of tListe
            put tFournisseur into char 117 to 136 of line i of tListe
            put "          " into char 137 to 146 of line i of tListe
            repeat while (i < the num of lines of tListe) and (char 2 to 3 of line i+1 of tListe <> "08")
               add 1 to i
               if char 22 to 41 of line i of tListe = tLibelle then
                  put tFournisseur into char 22 to 41 of line i of tListe
                  put tFournisseur into char 117 to 136 of line i of tListe
                  put "          " into char 137 to 146 of line i of tListe
               end if
            end repeat
         end if
      end if
   end repeat
   set the text of fld "ListeOperations" to tListe
   unlock screen
end mouseUp
Now the problem: running the script normally does not work. Some replacements in the data are simply missed.

If I put a breakpoint at the line "if char 2 to 3 of line i of tListe = "08" then" and if I use the Continue button of the script editor each time there is a break, the script performs correctly. So, I am not able to debug it, as it always performs correctly in debug mode.

Any ideas?

TIA
Best regards,

Didier

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm
Location: City of God Lug

Re: Converting from SuperCard

Post by LittleGreyMan » Sun Jun 17, 2012 9:02 am

Obviously, as it behaved differently in debug mode, the problem had to deal with the scope of the selection.

I had to change the way to reset the find command, which is not the same as in SC. The first attempt was not the good one, but switching to the debug window was reseting find. Hence this mistery.

I finally found the right command in LC Dictionary (RTFM!): find empty.
Best regards,

Didier

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Converting from SuperCard

Post by Mark » Sun Jun 17, 2012 6:41 pm

Hi,

I have nothing against "find", butI never use the find command. I always use an offset function, sometimes in combination with a repeat loop. This is also what I see most other developers do.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm
Location: City of God Lug

Re: Converting from SuperCard

Post by LittleGreyMan » Sun Jun 17, 2012 7:17 pm

Mark,

Thanks for your reply.

In this particular case, I need the second item of a line. Using find and getting the foundLine sounds more straightforward for me than getting an offset and parsing the item following this offset.

But maybe I'm wrong.
Best regards,

Didier

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Converting from SuperCard

Post by Mark » Sun Jun 17, 2012 7:26 pm

Hi,

You can do it in one line:

Code: Select all

put item 2 of line lineoffset(myVar,myData) of myData into myFoundItem
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm
Location: City of God Lug

Re: Converting from SuperCard

Post by LittleGreyMan » Sun Jun 17, 2012 8:36 pm

Mark wrote:Hi,

You can do it in one line:

Code: Select all

put item 2 of line lineoffset(myVar,myData) of myData into myFoundItem
Kind regards,

Mark
Definitely better than find, as it does not select anything. Thanks, Mark.
Best regards,

Didier

Post Reply

Return to “Converting to LiveCode”