Page 1 of 1

Variable check not correct?

Posted: Sat Feb 02, 2019 1:45 pm
by bogs
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?

Re: Variable check not correct?

Posted: Sat Feb 02, 2019 1:55 pm
by Klaus
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

Re: Variable check not correct?

Posted: Sat Feb 02, 2019 4:01 pm
by bogs
Image................ :oops:
Thanks Klaus, I was going a bit nuts on that one.

Re: Variable check not correct?

Posted: Sat Feb 02, 2019 11:27 pm
by [-hh]
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.

Re: Variable check not correct?

Posted: Sat Feb 02, 2019 11:43 pm
by bogs
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:

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 1:30 am
by [-hh]
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

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 11:27 am
by bogs
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:

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 11:42 am
by Thierry
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

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 12:04 pm
by bogs
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

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 12:48 pm
by Thierry
bogs wrote: If anything, you've made my day sunnier indeed :D
Then everything is perfect... :)

Re: Variable check not correct?

Posted: Sun Feb 03, 2019 3:03 pm
by bogs
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:

Re: Variable check not correct?

Posted: Mon Feb 04, 2019 1:42 pm
by bogs
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