Checkboxes and increasing size of fields

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Checkboxes and increasing size of fields

Post by Klaus » Thu Oct 24, 2013 9:53 pm

HI Brian,

please check my slighly modified and commented script:

Code: Select all

on mouseUp
  lock messages

  ## Speed up things!!!!
  lock screen

  put 0 into sTempVal
  put 16 into tLineHeight
  set the textHeight of fld "chkField" to tLineHeight
  
  ## This can be done ONCE outside the loop:
  set the style of the templateButton to "checkBox"
  set the showName of of the templateButton to false
  set the width of of the templateButton to 32 
  set the height of of the templateButton to tLineHeight
  
  repeat with x =1 to 10
    
    ## Try to avoid accessing fields in a repeat loop!
    ## Better collect all data fist and put then into the field!
    put "one" & CR after tChkField
    
    ## Better use PARENS around concatenated object names!
    ## Will save your life later, believe me :-D
    create button ("chk" & x)
    
    ## set the topRight of it to item 1 of the topRight of fld "chkField" + 0 & "," & item 2 of the topRight of fld "chkField" + sTempVal
    ## I think we cyn omit the + 0 part here ;-)
    set the topRight of it to item 1 of the topRight of fld "chkField" & "," & item 2 of the topRight of fld "chkField" + sTempVal
     add tLineHeight to sTempVal
  end repeat
  
  set the height of fld "chkField" to the textHeightSum of fld "chkField"
  set the topRight of fld "chkField" to the topRight of button "chk1"
  
  ## OK, this does not work at all this way!
  # create group "TickList"
  
  ## A field does not have any buttons!
  ##  put the number of buttons of "chkField" into tNosChk
  
  ## Although one would think that LC works this way, it doesnt :-/
  # repeat with x = 1 to tNosChk
  # put button "chk"&x into the group "Ticklist"
  # end repeat
  # put fld "chkField" into the group "TickList"
  
  ## We SELECT all objects we want to group, the GROUP them and name the LAST group:
  repeat with x = 1 to 10
    set the selected of button ("chk" & x) to TRUE
  end repeat
  
  ## Don't forget the field:
  set the selected of fld "chkField" to TRUE
  
  ## NOW:
  GROUP

  ## Give the new group the name you want:
  set the name of last grp to "Ticklist"

   ## Fill field with content:
   put tChkField into fld "chkField"
  
  ## Good style, to avoid later surprises:
  reset the templatefield

  ## Deselect all:
  select emtpy
  unlock messages
  unlock screen
end mouseUp
Best

Klaus

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

Re: Checkboxes and increasing size of fields

Post by jacque » Fri Oct 25, 2013 12:00 am

"The" is only used for built-in functions and properties. A group is an object, so remove the "the".

Built-in function examples:

the date
the loc
the textheight

Ex: put the date into field 1
Some people omit "the" for built-in functions and for the most part it works. It's a pet peeve of mine though, so I always use it.

Note that you can't use "the" with your own functions, those can only take parentheses. And yes, this is confusing. These would be functions I wrote for my own scripts:

listNames()
IBMdate()

Ex: put listNames(field 1) into var

All properties, yours or the built-in ones, require "the":

the customPropertySets
the cVersion -- my own custom property

Ex: get the customPropertySets of this stack
Ex: put the cVersion of this stack into tVersion

Object references never use "the" and will fail if you do:

group "mygroup"
button "click me"
field "username"

Ex: put the number of buttons in group "mygroup"
Ex: get the loc of button "click me"


Edit: I see Klaus has beaten me to it. Oh well, I was writing when he posted, I'll leave it here. :)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Checkboxes and increasing size of fields

Post by dunbarx » Fri Oct 25, 2013 12:03 am

Hi.

When you run into trouble, like your line: create group "TickList", it is always a good thing to go to the dictionary. There you will find that there is no acceptable syntax for "create group", only controls. These controls can be created "into" an existing group, as you will read.

So though it made sense in English, it did not in LC. Again, this just takes practice. But do take on the task of researching in the dictionary when either good things or bad things pop up.

Craig

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

Re: Checkboxes and increasing size of fields

Post by dunbarx » Fri Oct 25, 2013 12:04 am

Jacque.

It is getting to the point where beating Klaus is more important to me than posting useful replies. I am more and more concerned about that...

Craig

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

Re: Checkboxes and increasing size of fields

Post by jacque » Fri Oct 25, 2013 6:10 am

Okay, I admit it Craig, I laughed. :D
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Checkboxes and increasing size of fields

Post by Klaus » Fri Oct 25, 2013 11:27 am

dunbarx wrote:Jacque.
It is getting to the point where beating Klaus is more important to me than posting useful replies. I am more and more concerned about that...
Craig

Good luck, old chum :D

Tribblehunter
Posts: 78
Joined: Wed Apr 10, 2013 9:08 pm

Re: Checkboxes and increasing size of fields

Post by Tribblehunter » Sun Oct 27, 2013 12:10 pm

Thank you very much Klaus, Craig and Jaques.

This has improved my understanding of how to manipulate LiveCode so much.

Forwaeds with the next challenge (and probably a new thread!!)

Brian
Returning to try to learn livecode again.

But much greyer at the temples than the last time.

Tribblehunter
Posts: 78
Joined: Wed Apr 10, 2013 9:08 pm

Re: Checkboxes and increasing size of fields

Post by Tribblehunter » Sun Oct 27, 2013 12:18 pm

oh forgot one edit to code.

the lines

Code: Select all

 set the height of fld "chkField" to the textHeightSum of fld "chkField"
   set the topRight of fld "chkField" to the topRight of button "chk1"
i moved to line 30 the variable tChkField was put into field "chkField". It was not registering the textheightSum as there was no text in the field at that point.

hope you dont mind me ading this for future noobs like me.

Brian
Returning to try to learn livecode again.

But much greyer at the temples than the last time.

Post Reply