Delete line, row, record ?

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

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Delete line, row, record ?

Post by RossG » Mon Dec 07, 2015 1:56 am

I have in an array sets of numbers like "2,34,5,23" etc
and want to delete any set of numbers if a number
(say 34) appears again in another series of numbers.

I can put them into a field so could delete a "row" there
or else delete the "record" from the array perhaps.

I also want to "pack" the array or field after a delete
i.e remove blank "records".

Can't find anything to do either of these although no doubt it
can be done. Just need a push in the right direction.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Delete line, row, record ?

Post by dunbarx » Mon Dec 07, 2015 3:08 am

Hi.

Several ways to do what you want. Read about the "delete variable" command, which can delete a specific key in an array variable. You may also want to look at the "lineOffset" function, which would allow you to locate a string in a line in an ordinary variable, and delete it. That would work in a field as well, or any container.

As for packing a variable, you can always:

Code: Select all

repeat for each line tLine in yourVariable
  if tLine <> "" then put tLIne & return after accum
end repeat
answer accum
or

Code: Select all

repeat with y = the number of lines of yourVariable down to 1
  if line y of yourVariable = "" then delete line y of yourVariable
end repeat
answer yourVariable
That sort of thing.

Craig Newman

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Mon Dec 07, 2015 4:50 am

Craig

Spot on!

I see that your location is New York so if I say "I wish I was clever like you Brian"
it won't mean anything but if you were in England in the '70's you'd remember
the Cadbury's television advertisement in which the six-year-old boy explained
to his younger brother how they put the nuts in the chocolate.

Thank you!
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Mon Dec 07, 2015 7:01 am

I'm trying to use code from the Dictionary to step through an
array...
repeat for each line tKey in the keys of theArray

but in the debugger I see that it jumps over of the repeat loop.

Possible reasons anyone?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Delete line, row, record ?

Post by dunbarx » Mon Dec 07, 2015 4:27 pm

There are no "lines" that can be enumerated in an array. That is what takes a little getting used to. An array variable is not an ordinary variable, where chunk expressions may be applied. The fact that the debugger deconstructs an array variable into visible form WHILE STEPPING THROUGH is just a benefice.

What you wanted was

Code: Select all

repeat for each key tKey in theArray
Now step through...

Craig

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Mon Dec 07, 2015 11:40 pm

Well, the dictionary entry under "keys" says

repeat for each line....

So perhaps this should be corrected?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Delete line, row, record ?

Post by dunbarx » Tue Dec 08, 2015 12:26 am

No, no.

I mistook something, likely due to either overwork or sloppiness.

If you bring out "the keys", you indeed have an ordinary list, chunk accessible. What was the code that would not cycle through the lines of the keys?

Craig

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 1:38 am

So far I have the following:

repeat for each key tKey in theArray
if aVar is among the items of theArray[tKey] then
put tKey & CR after field fldArrayDisplay
put char 1 of tKey & CR after field fldArrayDisplay
---works so far---
put char 1 of tKey into sVar
--delete variable theArray[char 1 of tKey] --arrayIndex[char 1 of tKey]
--delete variable theArray[sVar]
--delete theArray[sVar]
end if
end repeat

Surprised to find that the key has the form "4,1" rather than "4".
Also surprised (for a moment) that they're listed "bottom up" but
then remembered that when one "line" is deleted the remaining
move up to fill the "gap".

You'll see from the code above that I haven't yet found the right
code to "delete variable".

Any ideas?

Note: After achieving the successful finding of the keys I went out
and bought myself a cigar.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 2:58 am

The answer to the above question is

delete variable theArray[tKey]

Worth another cigar don't you think?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 5:24 am

Now I'm trying to figure out how to add variable (record ?)
to the array.

Could anyone remind me how I can post this stack into
the "Resources" section so that everyone can have a go
at answering this question.

I'm out of cigars so no prize for the correct answer.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Delete line, row, record ?

Post by dunbarx » Tue Dec 08, 2015 5:38 am

That smoke has gone to your head, at least for the first part of your query:

Code: Select all

on mouseUp
   repeat with y =  1 to 10
      put y * 10 into tenTimes[y]
   end repeat
   
   put 150 into tenTimes[15} -- new "record"
end mouseUp
Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Delete line, row, record ?

Post by jacque » Tue Dec 08, 2015 10:29 am

dunbarx wrote:As for packing a variable, you can always:
My current favorite way to delete blank lines is a one-liner:

Code: Select all

filter tVar without empty
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 11:48 am

Craig

In the code you give you know that theArray[15] has nothing
in it. In my case I don't know so have to ascertain the next
index number.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 12:14 pm

I've put my test stack in Sample Stack with the name
"Array Manipulation".

A curiousity: seems that LC accesses arrays in a rather odd
DOS way i.e. in DOS if you highlight ten file to delete it will first
delete file 1 then file 10, file 9 etc. down to file 2.

Also note that deleted variables don't leave a blank line and
the remaining entries in the array keep their original index numbers
so the number of variables in the array can't be used to ascertain
the next index for adding a new variable.

Of course any of the above points might be the result of inept programming.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Delete line, row, record ?

Post by RossG » Tue Dec 08, 2015 12:29 pm

The search is over.

To add a variable to theArray...

repeat with x = 1 to 100
if theArray[x] = "" then
put "7,6,5,4,3,2,1" into theArray[x]
exit repeat
end if
end repeat
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.

Post Reply