Page 2 of 2

Re: Checkboxes and increasing size of fields

Posted: Thu Oct 24, 2013 9:53 pm
by Klaus
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

Re: Checkboxes and increasing size of fields

Posted: Fri Oct 25, 2013 12:00 am
by jacque
"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. :)

Re: Checkboxes and increasing size of fields

Posted: Fri Oct 25, 2013 12:03 am
by dunbarx
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

Re: Checkboxes and increasing size of fields

Posted: Fri Oct 25, 2013 12:04 am
by dunbarx
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

Re: Checkboxes and increasing size of fields

Posted: Fri Oct 25, 2013 6:10 am
by jacque
Okay, I admit it Craig, I laughed. :D

Re: Checkboxes and increasing size of fields

Posted: Fri Oct 25, 2013 11:27 am
by Klaus
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

Re: Checkboxes and increasing size of fields

Posted: Sun Oct 27, 2013 12:10 pm
by Tribblehunter
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

Re: Checkboxes and increasing size of fields

Posted: Sun Oct 27, 2013 12:18 pm
by Tribblehunter
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