How to get contents of a field into variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to get contents of a field into variable
Hi all,
Im very new to LiveCode, ive got a basic sqllite db set up and can insert values that are hard coded from Live Code. My next objective is to figure out how to create forms with lists, radiobuttons, and data entry fields so the data is dynamic.
I've placed a "Text Entry Field" onto my layout and Ive not quite figured out how to get the contents/values of that field into a variable. Ive named the field "Name" and I thought something like the line below would work (Ive gone through different variations)
put the data of field "Name" into tName
any help would be great. Are option menus, combo boxes etc treated differently?
Many thanks
Im very new to LiveCode, ive got a basic sqllite db set up and can insert values that are hard coded from Live Code. My next objective is to figure out how to create forms with lists, radiobuttons, and data entry fields so the data is dynamic.
I've placed a "Text Entry Field" onto my layout and Ive not quite figured out how to get the contents/values of that field into a variable. Ive named the field "Name" and I thought something like the line below would work (Ive gone through different variations)
put the data of field "Name" into tName
any help would be great. Are option menus, combo boxes etc treated differently?
Many thanks
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: How to get contents of a field into variable
Don't overthink it...
but you can also get the menuHistory of those controls.
Code: Select all
put field "Name" into tName
Yes. I don't have this in front of me right now, but it's either the label of the option menu or combo box or something similar, as inAre option menus, combo boxes etc treated differently?
Code: Select all
put the label of button "btnOptionMenu" into tSelection
Last edited by mwieder on Wed Jan 04, 2012 1:04 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: How to get contents of a field into variable
...and if you want to populate a dropdown list dynamically, all you have to do is
where tList is a cr-separated list of menu options.
Code: Select all
put tList into button "btnOptionMenu"
Re: How to get contents of a field into variable
Hi Guys,
Thanks for replying. Ive tried that but it says no such column: Jalz (Jalz being what I typed into the Name field).
I've got my complete code here below with the insert command - perhaps I'm doing something majorly wrong??? I've now split the name field into FName and SName and will be adding in the other citeria on the form once Ive sussed this bit out....
Many thanks
Thanks for replying. Ive tried that but it says no such column: Jalz (Jalz being what I typed into the Name field).
I've got my complete code here below with the insert command - perhaps I'm doing something majorly wrong??? I've now split the name field into FName and SName and will be adding in the other citeria on the form once Ive sussed this bit out....
Many thanks
Code: Select all
put field "FName" into tFName
put field "SName" into tSName
put "INSERT INTO Customer (FName, SName) " into tSQL
put "VALUES (" & tFName & ", " & tSName & ");" after tSQL
revExecuteSQL conID, tSQL
if the result is not 1 then
answer warning the result
exit to top
end if
Re: How to get contents of a field into variable
First name and last name are strings, they need to be quoted.
One way to do this would be to modify tFName and tSName after you fill their values
Something like
put "'" before tFName
put "'" after tFName
## Note its a ' single tick. So say your first name is Mike, you end up with 'Mike' in the tFName variable.
Do the same for surname and it should work. Don't quote numbers of course.
One way to do this would be to modify tFName and tSName after you fill their values
Something like
put "'" before tFName
put "'" after tFName
## Note its a ' single tick. So say your first name is Mike, you end up with 'Mike' in the tFName variable.
Do the same for surname and it should work. Don't quote numbers of course.
jalz wrote:Hi Guys,
Thanks for replying. Ive tried that but it says no such column: Jalz (Jalz being what I typed into the Name field).
I've got my complete code here below with the insert command - perhaps I'm doing something majorly wrong??? I've now split the name field into FName and SName and will be adding in the other citeria on the form once Ive sussed this bit out....
Many thanks
Code: Select all
put field "FName" into tFName put field "SName" into tSName put "INSERT INTO Customer (FName, SName) " into tSQL put "VALUES (" & tFName & ", " & tSName & ");" after tSQL revExecuteSQL conID, tSQL if the result is not 1 then answer warning the result exit to top end if
-
- VIP Livecode Opensource Backer
- Posts: 3581
- Joined: Mon Jan 22, 2007 7:36 am
- Location: Berkeley, CA, US
- Contact:
Re: How to get contents of a field into variable
Or, if you're going to be doing a lot of this, you might want to create a function to surround the names in quotes, ala Ken Ray:
and then your line of code could become
Code: Select all
function q pText
-- return the text surrounded by single quotes
return "'" & pText & "'"
end q
Code: Select all
put "INSERT INTO Customer (" & q("FName") & comma & q("SName" & ") " into tSQL
Re: How to get contents of a field into variable
Hi Guys,
Thanks all for taking the time out - got sturgis' example to work. mwieder thanks for the function, does make the code look more elegant, Ive made it work - but I changed the code you gave me to
Thanks again
Jalz
Thanks all for taking the time out - got sturgis' example to work. mwieder thanks for the function, does make the code look more elegant, Ive made it work - but I changed the code you gave me to
Code: Select all
put "VALUES (" & q(tFName) & ", " & q(tSName) & ");" after tSQL
Jalz