Page 1 of 1

Converting from SuperCard

Posted: Sat Jun 16, 2012 8:55 pm
by LittleGreyMan
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

Re: Converting from SuperCard

Posted: Sun Jun 17, 2012 9:02 am
by LittleGreyMan
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.

Re: Converting from SuperCard

Posted: Sun Jun 17, 2012 6:41 pm
by Mark
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

Re: Converting from SuperCard

Posted: Sun Jun 17, 2012 7:17 pm
by LittleGreyMan
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.

Re: Converting from SuperCard

Posted: Sun Jun 17, 2012 7:26 pm
by Mark
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

Re: Converting from SuperCard

Posted: Sun Jun 17, 2012 8:36 pm
by LittleGreyMan
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.