Page 1 of 2
Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 6:22 pm
by Tribblehunter
Hi again.
Learning fast with livecode! Can make pdf's now!!
Quick questions now I am moving on.
Can i add check boxes to a card by code?
Will a field increase in size as more lines are added?
Am populating fields from list dependent on selections and adding checkboxes also as more lines are added.
Hope this makes sense.
Tribblehunter
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 7:51 pm
by dunbarx
Hi.
You can create a button using the, er, "create" command. You would have to set its properties, or possibly set up the "templateButton" to do it for you. Read up a bit on all those.
Fields will not increase in size unless you tell them to, which is certainly possible, and a fun mini-project.
If you need more help with any of this, write back, but it is all basic stuff, and the legwork will do you good.
Good luck, and do not hesitate to post again if you get stuck.
Craig Newman
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 8:09 pm
by Tribblehunter
Thanks Craig.
Just found the create command in the dictionary.
am looking for the 'resize' commands now.
WooHoo!
another thing learnt. lol
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 8:23 pm
by dunbarx
Hi again.
Though many, many times it works, sometimes you will not find a logical LC word that fulfills your needs. There is no "resize" command, unless you write your own.
Which you should do. This would be terrific homework.
But you will benefit by looking at the "rect", "height" and similar commands. And also check up on the "resizeControl" message. This is not a command, but you may find it useful. Working through the dictionary takes time and a little luck. But it is all there, and very accessible. Be sure always to check out the "see also" entries even if you do not find exactly what you need.
Craig
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 8:29 pm
by Tribblehunter
Thanks Craig.
Only been playing with this for a week after using App inventor.
Looking to put a series of check boxes into a list created from user choices. Am now seeing how to put the check boxes 'into' a field.
May be back for more pushes in the right direction soon!
Brian
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 9:43 pm
by Tribblehunter
Got how to position check boxes in field.
Code: Select all
on mouseUp
lock messages
local tempVal = 0
repeat with x =1 to 10
set the style of the templateButton to "checkBox"
create button "chk"& x
set the showName of it to false
set the width of it to 32
--set the topRight of it to the topRight+tempVal of fld "chkField"
add the textHeightSum of line 1 of fld "chkField" to tempVal
end repeat
unlock messages
end mouseUp
but the commented section (where i want to add the next check box on the next line) does not appear to work.
I know I will find the answer but its late here and i wanted to nail this before i hit the sack.
Any pointers? much appreciated.
Brian
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 9:52 pm
by jacque
You've almost got it, just needs a little rearranging:
set the topRight of it to the topRight of fld "chkField" +tempVal
The field reference has to be complete every time you use it.
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 10:11 pm
by dunbarx
What Jacque said.
Do you see what tripped the engine up? Your "tempVal" is a variable, and may be used just as you did. It is stored in memory, probably contains data, and is referred to strictly by name. But the "topRight" is a property, and always is married to an object. You are not giving LC any information about the control that "holds" the property, so it complained.
Just takes practice to learn the handful of essential language components. Look at the bottom half of the dictionary sidebar, under "Language". All nine classes are listed there. Check out the "Object" listing as well.
Craig
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 10:51 pm
by Tribblehunter
Thanks guys. Will give that a try. Tomorrow!
Brian
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 10:57 pm
by jacque
Just noticed something. TopRight is a 2-item list. TempVal is a single integer. What you're asking for is to add an amount to something like "123,592".
Depending on what you want, you'll either need to add the amount to each item individually (a diagonal adjustment) or to one or the other of the items (horizontal or vertical adjustment.)
Re: Checkboxes and increasing size of fields
Posted: Wed Oct 23, 2013 11:02 pm
by Tribblehunter
Ah i see.
So i need to get position of top right of field then work it out from there.
sounds like fun to me! my day job is fixing boats so this is a pleasant distraction. Lol.
Brian
Re: Checkboxes and increasing size of fields
Posted: Thu Oct 24, 2013 9:40 am
by Tribblehunter
OR.....
turn tempVal into a 2 item list. eg
on mouseUp
lock messages
local tempVal = 0
repeat with x =1 to 10
set the style of the templateButton to "checkBox"
create button "chk"& x
set the showName of it to false
set the width of it to 32
set the topRight of it to the topRight of fld "chkField" + (top position (0) +tempVal,right position (0))
add the textHeightSum of line 1 of fld "chkField" to tempVal
end repeat
don't think this will work in that form but not able to test ATM. just wanted to get the thought down so i don't loose it.
Re: Checkboxes and increasing size of fields
Posted: Thu Oct 24, 2013 2:13 pm
by dunbarx
Hi.
Do it the old fashioned way. It will help keep the items straight:
set the topRight of it to item 1 of the topRight of fld "chkField" + someInteger & "," & item 2 of the topRight of fld "chkField" + someOtherInteger.
See? If the topRight is of the form "x,y", and you want to do some arithmetic to that compound value, you must deal with the elements of that value separately. As Jacque pointed out, nobody and no program knows how to add, say, a "5" to "3,4". But you can add "5" to item 1 of "3,4", to get "8,4"
Craig
Re: Checkboxes and increasing size of fields
Posted: Thu Oct 24, 2013 7:40 pm
by Tribblehunter
Excellent Craig! That helps me understand the syntax and operation of livecode better.
Thank you for the help and advice. This noob is now a noob +someInteger
Brian
Re: Checkboxes and increasing size of fields
Posted: Thu Oct 24, 2013 9:21 pm
by Tribblehunter
Ok. moving on slowly.
Have managed to get all chkBoxes lined up with text.
Now trying to group together to see if I can lock them to the field.
Code: Select all
on mouseUp
lock messages
local sTempVal = 0
set the textHeight of fld "chkField" to 16
put the textHeight of fld "chkField" into tLineHeight
repeat with x =1 to 10
put "one"&cr after fld "chkField"
set the style of the templateButton to "checkBox"
create button "chk"& x
set the showName of it to false
set the width of it to 32
set the height of it to tLineHeight
set the topRight of it to item 1 of the topRight of fld "chkField" + 0 & "," & 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"
create group "TickList"
put the number of buttons of "chkField" into tNosChk
repeat with x = 1 to tNosChk
put button "chk"&x into the group "Ticklist"
end repeat
put fld "chkField" into the group "TickList"
unlock messages
end mouseUp
its the 'group' command I am getting wrong I know. So I am posting this here and going to call it a night.
Thanks in advance to any who wish to push me in the right direction.
Brian