SOLVED - How do I get the current selection of a combobox

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

SOLVED - How do I get the current selection of a combobox

Post by admin12 » Mon Jul 25, 2011 7:19 pm

The following code draws an error and tells me no such object exists around "fldGender"

Now fldGender is a combo box where you can either choose Male or Female.

Here is the code:

================================================

--Now save to CandidateCC

put the text of field "MonthEntry" &space & the text of field "DayEntry" &comma & space & the text of field "YearEntry" into DOB

--answer DOB

put "INSERT INTO candidatecc (CandidateCCID,FirstName,MiddleName,SurName,Gender,DOB,EmailAddr,PrimTele,ecn,skype,promo_code) VALUES ("&CandidateCCID & "," &numtochar(39) & the text of field "fldFirstName" &numtochar(39) & "," &numtochar(39) & the text of field "fldMiddleName" &numtochar(39) & "," &numtochar(39) & the text of field "fldSurName" &numtochar(39) & "," & the text of field "fldGender" &numtochar(39) &numtochar(39) & "," &numtochar(39) &DOB &numtochar(39) & "," &numtochar(39) & the text of field "fldEmailAddr" &numtochar(39) & "," &numtochar(39) & the text of field "fldPhoneNum" &numtochar(39) & "," &numtochar(39) & the text of field "fldEmergencyNum" &numtochar(39) & "," &numtochar(39) & the text of field "fldSkype" &numtochar(39) & "," &numtochar(39) & the text of field "fldPromoCode" &numtochar(39) & "," & ")" into theQuery3

answer theQuery3

revExecuteSQL dbID, (theQuery3)

answer "Information saved"

=====================================================

Can anyone help me spot the problem or is there a different way to deal with a combo box (other than 'the text of field "fldGender"')

Thanks.

Mike
Last edited by admin12 on Thu Jul 28, 2011 7:30 pm, edited 3 times in total.

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: I just cannot find the culprit here

Post by dglass » Mon Jul 25, 2011 8:13 pm

The text of a combobox is the list of options. The label is the text of the selection, or whatever was typed into the entry area.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: I just cannot find the culprit here

Post by bn » Mon Jul 25, 2011 8:20 pm

Hi Mike,

a combobox is a button, not a field. To get at the current selection of a combobox use the menuhistory. It is a number corresponding to the line number of the text of the button "myComboboxButton"

Code: Select all

on mouseUp
   put line (the menuhistory of btn "gender") of the text of btn "gender" into field 1
end mouseUp
or a little shorter:

Code: Select all

on mouseUp
put line (the menuhistory of btn "gender")  of btn "gender" into field 1
end mouseUp

You might want to put numtochar(39) into a variable / constant. It saves a lot of typing and makes your code easier to read.

Code: Select all

put numtochar (39) into SQ
It would also be helpful for others that just read the topic of your post if it would be more specific. Like: "How do I get the current selection of a combobox" or somesuch.

Kind regards

Bernd

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: I just cannot find the culprit here

Post by admin12 » Mon Jul 25, 2011 8:26 pm

Great ideas. Still not fixed.

Mike

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: How do I get the current selection of a combobox

Post by admin12 » Thu Jul 28, 2011 4:17 pm

Still not fixed, but I will try the above and see what happens.

How would I populate the combobox with saved data from the database. I can populate all the other fields, but comboboxes seem to elude me.

So, for example,

set the itemDel to tab
repeat for each line myLine in theData
put item 1 of myLine into field "fldCityBirth"
put item 2 of myLine into field "Country1"
put item 3 of myLine into field "Country2"
put item 4 of myLine into field "Country3"
put item 5 of myLine into field "fldVidLink"
put item 6 of myLine into field "fldRef1"
put item 7 of myLine into field "fldRef2"
put item 8 of myLine into field "fldRef3"
put item 9 of myLine into field "fldCert"
put item 10 of myLine into field "fldPassBioPage"
put item 11 of myLine into field "fldProofSS"
put item 12 of myLine into field "fldPoliceBC"
put item 13 of myLine into field "fldTandC"
put item 14 of myLine into field "cmbIntNotes"
put item 15 of myLine into field "fldContract"

end repeat

populates the fields with existing data after I read it from the database with a SELECT query.

However, the Countries are not fields, but comboboxes. How do I populate those properly?

I also tried:

put item 2 of myLine into the text of btn "Country1"

and

put item 2 of myLine into btn "Country1"

Neither worked?

Mike

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

Re: How do I get the current selection of a combobox

Post by Klaus » Thu Jul 28, 2011 6:15 pm

Hi Mike,

you are looking for the LABEL property!
..
set the label of btn "Country1" to item 2 of myLine
...


Best

Klaus

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: How do I get the current selection of a combobox

Post by admin12 » Thu Jul 28, 2011 7:30 pm

That did it. Thank you.

Mike

Post Reply