Page 1 of 1
Handling situations where a requested card doesn't exist
Posted: Sun Nov 01, 2020 6:42 pm
by glenn9
Hi everyone,
I just wanted to check if there was a way of handling the situation of when issuing a 'go to Card 1' command but where 'card 1' doesn't exist?
i guess something along the lines of...
Code: Select all
go to card selectedText of me
if card selectedText of me 'doesn't exist' then...
(delete the selectedText of me)
Grateful for any advice.
Kind regards,
Glenn
Re: Handling situations where a requested card doesn't exist
Posted: Sun Nov 01, 2020 7:10 pm
by jmburnod
Hi Glenn,
You may use
Code: Select all
if there is a cd "MyCard" then go to cd "MyCard"
Kind regards
Jean-Marc
Re: Handling situations where a requested card doesn't exist
Posted: Sun Nov 01, 2020 7:18 pm
by glenn9
Thanks Jean-Marc, this was very helpful. I've also discovered the command 'exists' in the dictionary
Code: Select all
if exists(card selectedText of me) then
go to card selectedText of me
Kind regards,
Glenn
Re: Handling situations where a requested card doesn't exist
Posted: Sun Nov 01, 2020 10:13 pm
by FourthWorld
FWIW "the result" will inform you if you attempted to go to a card that doesn't exist.
Re: Handling situations where a requested card doesn't exist
Posted: Mon Nov 02, 2020 5:16 am
by dunbarx
It is hardly important in any useful sense, but there is *always* a card 1.
Craig
Re: Handling situations where a requested card doesn't exist
Posted: Mon Nov 02, 2020 9:59 am
by glenn9
Thank you
I guess what I was wanting to achieve was to delete from a list the line that is no longer linked with a card (because the linked card had been previoulsy deleted), I want to to delete the 'orphaned' line by script.
I've now achieved this through:
Code: Select all
on mouseup
if exists(card selectedText of me) then
go to card selectedText of me
else
put hilitedLine of field"List" into toDelete
delete line toDelete of field"List"
...
However... enough is not enough, so I now want to delete the line from the list at the time of the linked card deletion and have got as far as this with code but struggling to somehow 'hilite' or 'indicate' the line in the list so it can be deleted...
Code: Select all
-- sent from the card that is to be deleted, ie not card"Main"
if field"List" of card "Main" contains toDelete then
answer the hilitedtext of fld "Field" of card"Main"
The code above works as expected but I'm struggling to code the subsequent 'delete the line' command
...any thoughts? (if any of this makes sense to third parites reading this...!)
regards,
Glenn
Re: Handling situations where a requested card doesn't exist
Posted: Mon Nov 02, 2020 3:38 pm
by dunbarx
Hi.
Can't you use the "deleteCard" message, which is sent just before the card is actually deleted, to update your list?
Craig
Re: Handling situations where a requested card doesn't exist
Posted: Mon Nov 02, 2020 4:42 pm
by glenn9
Thank you all for your help.
Apologies for the lack of clarity in my question but have now managed to solve my difficulty.
I stumbled across the 'lineoffset' command in the dictionary which gave me the answer.
Just in case its of use to anyone, what I basically wanted to do was to delete a line of a list that contained some defined text.
so what I did was:
- put the text into a variable
- put the variable into the lineoffset command
- this told gave me the line number that the text was in
- and so I was then able to delete that line
The code looked like this:
Code: Select all
if field"Field" of card "Main" contains tTextToDelete then
go to card"Main"
put lineoffset(tTextToDelete, field"Field") into tLinetoDelete
delete line tLinetoDelete of field"Field"
I was particularly proud of myself as I'd not come across the lineoffset command before and managed to use it successfully!
Everyday a new livecode learning event... yesterday it was the 'exists' command!
Thank you again,
Glenn
Re: Handling situations where a requested card doesn't exist
Posted: Tue Nov 03, 2020 8:26 pm
by jiml
what I basically wanted to do was to delete a line of a list that contained some defined text.
You may find the FILTER command useful too.
Code: Select all
filter fld "myField" without "*tTextToDelete*"
Re: Handling situations where a requested card doesn't exist
Posted: Wed Nov 04, 2020 1:59 pm
by glenn9
jiml wrote: ↑Tue Nov 03, 2020 8:26 pm
what I basically wanted to do was to delete a line of a list that contained some defined text.
You may find the FILTER command useful too.
Code: Select all
filter fld "myField" without "*tTextToDelete*"
Thank you jiml, an elegant solution, another piece of learning for me.
Regards,
Glenn