Fields and lines...[Solved]

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Fields and lines...[Solved]

Post by bogs » Sun Dec 23, 2018 1:11 pm

I hope someone can set me straight on this behavior, as I am unable to figure out why it is happening.

I have a simple stack, with a field on it.
.. in the field are a number of lines.
.. I am trying to replace 2 of the lines without changing the placement of the rest of the lines.
Here are the lines I am working with -

Code: Select all

[Desktop Entry]
Version=1.0
Type=Application
Name=BubbleTimer
Comment=Simple time length recording timer.
Icon=/home/bogs/Lc_Projects/Lc6_5-6_7/bubbleTimer/bubbleIcon2.svg
Exec=/home/bogs/Lc_Projects/Lc6_5-6_7/bubbleTimer/BubbleTimer
StartupWMClass=BubbleTimer
Terminal=false
I want to replace lines 6 & 7 with strings in variables, so my thinking originally ran to the simplest commands I could come up with,

Code: Select all

 put "icon=" & tmpPath & tmpFiles into line 6 of field 1
 put "Exec=" & tmpPath & tmpName into line 7 of field 1
In this case, tmpPath and tmpFiles hold the location of a picture and the path to an exectuable, tmpName holds the exectuables name.

However, when running the code, the field goes from this -
Create Linux Desktop Launcher Automatically..._001.png
Original...
To this -
Create Linux Desktop Launcher Automatically..._002.png
Wth ?
Which looks like at least one line not worked with got blipped out (Comment=), and empty lines added.

I've tried instead using replace, replaceText, deleting the line then putting it into the line, inserting before or after the line then deleting the next line (which kind of works), but I am stumped as to why it can't just be put into the original line without moving or removing other lines :roll:

Thank you in advance for any information provided :D
Last edited by bogs on Mon Dec 24, 2018 11:54 am, edited 1 time in total.
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Fields and lines...

Post by [-hh] » Sun Dec 23, 2018 2:39 pm

You could check the line endings of your field before replacing.
Probably this is copied from a file that has "mixed" line endings.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Sun Dec 23, 2018 2:54 pm

Hm. That certainly is a thought that never occurred to me, the text was created in a basic text editor (Leafpad) on a linux system (antiX) and then copied/pasted into the field. It would be wierd if the line endings were mixed in type, but not impossible. I'll check that and then come back with the results.

Edit - the results ~
Far as I can tell, the file doesn't contain mixed endings. I ran a number of check commands.
Selection_003.png
Checking CRLF status...
All came back clean.

Edit 2 -
Just to make sure I hadn't made a mistake from the command line, I opened the file in Geany.
Selection_004.png
Geany, show me the line endings!
Last edited by bogs on Sun Dec 23, 2018 3:10 pm, edited 1 time in total.
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Fields and lines...

Post by [-hh] » Sun Dec 23, 2018 3:09 pm

If you do such inserting by script(put url(...)) then you should also make sure that the file is UTF-8 (for LC 8/9).
Also I saw that you use versions < 8 with this project. If you switch between LC 6 and LC 8/9, then line ending problems may also occur.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Sun Dec 23, 2018 3:16 pm

[-hh] wrote:
Sun Dec 23, 2018 3:09 pm
If you do such inserting by script...
In this case, the text is simply copied from Leafpad to the field. Only which lines need to be changed are scripted. Good thought though!

The versions of the IDE I use are Mc, and Lc 6.5.2 primarily. I don't use versions higher than that unless I am trying to answer someone elses question, so no worry on bringing it up to 8 :D

In this case, it is straight Lc 6.5.2.

From your answers, am I right in assuming that putting the text directly into line x of field x *should* work the way I am thinking?
Image

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Fields and lines...

Post by [-hh] » Sun Dec 23, 2018 3:27 pm

It should work if your insertions are one line (don't contain return), else you should replace first line 7, then line 6.

Of course LC converts text from clipboards when pasting.
Better try to get the file via
• url("file:"&....) -- converts line endings
• url("binfile:"&...) -- doesn't convert line endings

and see if there is a difference.
shiftLock happens

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Sun Dec 23, 2018 3:54 pm

Hmm, I wasn't planning on including the text file in use, the field is where the original would be kept, but just to make sure, I tested your suggestion.

The code to load the file -

Code: Select all

  put  url("file:" & tmpPath & "/lines.text") into field 1
which appears correct -
Selection_005.png
Loaded text...
but I still get the goofy result when changing the 2 lines I need changed -
Selection_006.png
Hmmm....
Just to make sure I wasn't outputting some goofy mixed format, I checked the file being written as well -
Selection_007.png
LF all the way, yaaayyy!
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Fields and lines...

Post by richmond62 » Sun Dec 23, 2018 5:39 pm

Try making sure your field is a scrolling list field:
-
brains.png
brains.png (12.31 KiB) Viewed 5367 times
-

Code: Select all

on mouseUp
   put "monkey's brains" into line 1 of fld "f1"
   put "cauliflowers" into line 3 of fld "f1"
   put "risorgimento" into line 7 of fld "f1"
end mouseUp

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Sun Dec 23, 2018 5:54 pm

After reviewing Hermann's input again, I manually typed the entries into a separate field, then put that fields contents into the field that will be edited just to make sure Lc was playing with all the same marbles as it were, but still no joy :?
Create Linux Desktop Launcher Automatically..._008.png
Top field manually typed in, copied to lower field, then lower field edited by script...
Before the lines are inserted through script, the bottom and top field are identical.
richmond62 wrote:
Sun Dec 23, 2018 5:39 pm
Try making sure your field is a scrolling list field:
The fields I am using are just base fields (with scrollbars checked), but shouldn't putting the line into the field work without creating this kind of havoc regardless?

The code that is causing this is just

Code: Select all

put "icon=" & tmpPath & tmpFiles into line 6 of field 1
No cr, no return, no LF, just trying to replace one line with the new line.
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Fields and lines...

Post by richmond62 » Sun Dec 23, 2018 6:01 pm

but shouldn't putting the line into the field work without creating this kind of havoc regardless?
I have a funny feeling line numbers don't behave themselves in "plain, vanilla" text fields.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Sun Dec 23, 2018 10:09 pm

Hmmmm.... :|

Edit - Following Richmond's suggestion, I substituted a scrolling list field for the base field and fed in the same code, and got the same result.
Selection_001.png
Hmmmm....
Me thinks I is beginning to smell a bug :cry:

Edit 2 - I see the same result on Win7 in 9.0.1, so I'll go check the bug reports now.
Win7Tester [Running] - Oracle VM VirtualBox_002.png
Win7 Lc 9.0.1...
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...

Post by bogs » Mon Dec 24, 2018 12:07 am

Well, I finally did figure out what (or I should say, *where*) was going wrong in the code for me, it isn't a bug though :?

Here is the code that starts the issue -

Code: Select all

 put "" into tmpFiles // clear tmpFiles...
   repeat for each line x in the files
 // this puts an extra empty line at the end of the list I didn't take into account ...
      put x & cr after tmpFiles
   end repeat
   filter tmpFiles without "*.*"
   // put the name into the correct location in the field...
   put tmpFiles into tmpName
    put "Name=" & tmpName into line 4 of tmpFieldContents
Of course, that unaccounted for (by me) empty line caused the whole problem, by shifting the number of lines in the field, which I corrected with this change

Code: Select all

// put the name into the correct location in the field...
   put line 1 of tmpFiles into tmpName
Here is the picture proof of my own idiocy :oops:
Selection_003.png
What a dingbat!
Image

I certainly want to thank Hermann and Richmond for the suggestions, sorry for the false alarm :oops:
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Fields and lines...[Solved]

Post by jacque » Mon Dec 24, 2018 7:36 pm

There is a religious war about whether line (and other) ending characters should be delimiters or simply markers that are part of the text chunk. The current behavior is to consider them as part of the chunk, and that works well in more situations than delimiters would. LC strips off the marker when you ask for the contents of the chunk, otherwise it remains.

If that's a problem, the usual fix is to remove the last marker (CR in this case) before manipulating the field. Or just filter the resulting field "without empty" after an operation that affects the results.

Mark Waddingham provided a good explanation for why these markers could not be used as delimiters but I can't remember where it is.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fields and lines...[Solved]

Post by bogs » Mon Dec 24, 2018 8:48 pm

jacque wrote:
Mon Dec 24, 2018 7:36 pm
There is a religious war about whether line (and other) ending characters should be delimiters or simply markers that are part of the text chunk.
You know, I'll believe whatever you tell me too, 'o mighty 'o powerful omnipotent shtomper!
Image
jacque wrote:
Mon Dec 24, 2018 7:36 pm
the usual fix is to remove the last marker (CR in this case)
Yah, if I had known there was an empty line below the one I had needed after filtering tmpFiles, I would have saved myself a lot of frustration Image

Somehow, though, it never occurred to me there was an empty line to deal with until I stepped through it, and even then I stared at that variable for hours. If I had just stuck a cursor in there at *any* point, or counted the lines of it, or any number of other things that would have equaled more than '1', the agony would have been far less :?

I swear my brains go out on random walks of their own when I'm not looking :P but hopefully this page will save some other poor soul some headscratching :twisted:
Last edited by bogs on Mon Dec 24, 2018 8:52 pm, edited 1 time in total.
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9359
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Fields and lines...[Solved]

Post by richmond62 » Mon Dec 24, 2018 8:49 pm

There is only one thing that has to be considered, decided on,
and THEN made explicit in the documentation.

And that is whether a "bog normal" textField has line number that can be addresst
in the same way as lines in a scrolling list field can be addresst or not,
and if they can't it micht be time to introduce a text field that is NOT scrolling but is STILL a list field and
plonk an icon for that on the toolbar.rev palette.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”