Variable check not correct?

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
bogs
Posts: 4007
Joined: Sat Feb 25, 2017 10:45 pm

Variable check not correct?

Post by bogs » Sat Feb 02, 2019 1:45 pm

I was playing with routines to find different ways of checking what is in a variable, when I hit this.

The stack has only 2 radio buttons grouped.
I check to make sure the target is one of the 2 buttons
I put the 2nd word of the name into a variable
I delete the superfluous characters
This is the code I'm using for this test -

Code: Select all

on mouseUp
   if character 2 to 4 of word 2 of the target is "rdo" then
      put word 2 of the target into tmpVar
      delete character 2 to 4 of tmpVar
      if tmpVar is "One" then answer "One"
      if tmpVar is "Two" then answer "Two"
   end if
end mouseUp
When I check to see which of the 2 buttons are selected, even though the variable shows one of the two, apparently it is ignored :|
Selection_002.png
One, Two, ...?
I checked the variable for spaces, returns, all kinds of other stuff that would tell me why this is failing to identify either one or two in the variable.

What am I missing?
Image

Klaus
Posts: 11335
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Variable check not correct?

Post by Klaus » Sat Feb 02, 2019 1:55 pm

Hi Bogs,

the target = button "rdoOne"
word 2 of the target = "rdoOne" # WITH Quotes!
...
delete character 2 to 4 of tmpVar
## -> "One", still WITH Quotes!
## So tmpVar is in fact ""One""
## Add this:
replace QUOTE with "" in tmpVar
...
So you should:
a. check the short name of the target or
b. use -> put trueword 2 of the target into tmpVar

Best

Klaus

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

Re: Variable check not correct?

Post by bogs » Sat Feb 02, 2019 4:01 pm

Image................ :oops:
Thanks Klaus, I was going a bit nuts on that one.
Image

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

Re: Variable check not correct?

Post by [-hh] » Sat Feb 02, 2019 11:27 pm

Why don't you simply script the group as follows?

Code: Select all

on mouseUp
   answer the hilitedButtonName
end mouseUp
or replace in your script the last two lines with:

Code: Select all

answer tmpVar
Then you see the quoted content of tmpVar.
shiftLock happens

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

Re: Variable check not correct?

Post by bogs » Sat Feb 02, 2019 11:43 pm

Excellent tips all round -hh & Klaus :D

Klaus, if you want to you can move this to the 'complete beginners' section for me, since it is (now clear to me) obviously not a bug.

@ -hh
When I thought this was a bug, the code I wrote to work around it wound up being

Code: Select all

on mouseUp
   if character 2 to 4 of word 2 of the target is "rdo" then
      put the short name of the target into tmpSortBy
      // {sort by example address}  http://lists.runrev.com/pipermail/use-livecode/2019-January/date.html#start
      if tmpSortBy is "rdoSubject" then
         put "/subject.html" into tmpSortBy
      else if tmpSortBy is "rdoThread" then
         put "/thread.html" into tmpSortBy
      else if tmpSortBy is "rdoAuthor" then
         put "/author.html" into tmpSortBy
      else if tmpSortBy is "rdoDate" then
         put "/date.html" into tmpSortBy
      end if
   end if
   
   /* todo: code for [reply / save] buttons added here */
   
   openStack
end mouseUp
I can (and probably will) shorten this later, but for now it is adequate for what it has to do :)

I saw the quotes in the variable as you see in the picture in the first post there, but for whatever reason, my mind wasn't picking it up. All I kept thinking was the "One" in code was exactly what I was seeing in tmpVar. I make lots of silly mistakes like that, but usually I figure out what I'm missing before making a complete fool of myself :oops:
Image

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

Re: Variable check not correct?

Post by [-hh] » Sun Feb 03, 2019 1:30 am

In order to support your steep learning curve. This does the same as your script.

Code: Select all

on mouseUp
  put the short name of the target into sn
  if sn begins with "rdo"
  then put "/" & lower(char 4 to -1 of sn) & ".html" into tmpSortBy
  openStack
end mouseUp
shiftLock happens

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

Re: Variable check not correct?

Post by bogs » Sun Feb 03, 2019 11:27 am

OOOOooooooo, I like that!

Thanks Hermann!

The learning curve isn't steep, so much as it was fractured, so I wind up coding in "baby talk" as it were :)

Funny thing is, even as childish as some of my code winds up being, it is still shorter than languages I am pretty confident in. Now I'll have to revisit some of those and figure out where I screwed up there :wink:
Image

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 664
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Variable check not correct?

Post by Thierry » Sun Feb 03, 2019 11:42 am

bogs wrote: OOOOooooooo, I like that!
Thanks Hermann!
The learning curve isn't steep, so much as it was fractured, so I wind up coding in "baby talk" as it were :)
Hi Sir bogs,

In the same spirit as Hermann, here are 2 other options to do it...

Code: Select all


   if matchText( the short name of the target, "^rdo(.*)$", aTopic )
   then put "/" & aTopic & ".html" into tmpSortBy
   
and of course, this one is my preferate:

Code: Select all


   get sunnYreplace(the short name of the target, "^rdo(.*)$", "/\1.html", tmpSortBy)

with the hope I didn't spoil your sunny sunday in Boston....

Kind regards,

Thierry
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

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

Re: Variable check not correct?

Post by bogs » Sun Feb 03, 2019 12:04 pm

I stand in pure AWE Thierry
Image

I definitely need to go through the dictionary again. It pains me to admit I was just using matchChunk and matchText in another little utility I was writing, but didn't think of them for this routine.

If anything, you've made my day sunnier indeed :D
Image

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 664
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Variable check not correct?

Post by Thierry » Sun Feb 03, 2019 12:48 pm

bogs wrote: If anything, you've made my day sunnier indeed :D
Then everything is perfect... :)
Thierry Douez - https://sunny-tdz.com
Pourquoi tant de notes lorsqu'il suffit de jouer les plus belles... [Barbara]

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

Re: Variable check not correct?

Post by bogs » Sun Feb 03, 2019 3:03 pm

Klaus wrote:
Sat Feb 02, 2019 1:55 pm
Hi Bogs,
<sic>
b. use -> put trueword 2 of the target into tmpVar
Although this will be great if I ever go to v7.x for my programming, it doesn't exist in the versions I currently use. It should be great for anyone that falls into this thread later though :wink:
Image

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

Re: Variable check not correct?

Post by bogs » Mon Feb 04, 2019 1:42 pm

After testing all the excellent suggestions made in this thread (thank you so much all), I chose this as the final solution -
I removed the test from mouseUp and put it into threadsFetch, eliminating the need to check the radioButton test completely in an 'if/then' type statement.

I then took 2 of -hh's suggestions in tandem, which led me to this line -

Code: Select all

on threadsFetch
   // get the sort method from which radio button is selected...
   put "/" & lower(character 4 to -1 of the hilitedButtonName of group "grpDisplay") & ".html" into tmpSortBy
Thank you all for getting me to re-think the whole situation, which greatly simplified the program flow.

*Edit - after a few 'duh' moments, I realized I could just grab the label of the button (although that took me a while to work out how) :D
The code now reads -

Code: Select all

put "/" & lower(the label of button(the hilitedButtonName of group "grpDisplay")) & ".html" into tmpSortBy
Image

Post Reply

Return to “Bug Triage”