Setting text into a button.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Setting text into a button.
I just put the following code
"...
set the label of btn "1006" to "Raise an invoice"
...
"
into a button, set different colors for text and background, and don't get the text on the button.
'Errors' shows 'No errors'
Any ideas please ?
"...
set the label of btn "1006" to "Raise an invoice"
...
"
into a button, set different colors for text and background, and don't get the text on the button.
'Errors' shows 'No errors'
Any ideas please ?
Re: Setting text into a button.
Sure its name is "1006"? Not "button id 1006"?
It is not recommended to name objects with NUMBERS!
Give your button a name and try again.
Or try this:
We need to address objects with their names or ID:
It is not recommended to name objects with NUMBERS!
Give your button a name and try again.
Or try this:
Code: Select all
...
set the label of btn id 1006 to "your string here..."
...
Code: Select all
...
set the label of btn "my button" to "your string here..."
...
set the label of btn id 1006 to "your string here..."
...
Re: Setting text into a button.
Yep pretty sure Klaus is on the money there.
1006 suggests an ID - so the button should be referred to as
btn ID 1006 (without any quotes).
1006 suggests an ID - so the button should be referred to as
btn ID 1006 (without any quotes).
Re: Setting text into a button.
I just entered
"
...
set the label of btn id 1006 to "Raise an invoice"
...
"
without success
"
...
set the label of btn id 1006 to "Raise an invoice"
...
"
without success
Re: Setting text into a button.
The only explanation to that is that the button does not have ID 1006....
Open the property panel for the button - if no name is assigned then the titlebar of the property panel should read button id xxxx (id xxxx), or else button "<button name>" (id xxxx) - make sure the ID you're using is correct.
i just made new button that was given the id 343434.
Code: Select all
set the label of button id 343434 to "test"
Alternatively, and this would be my preference, you can name the button (easier to remember) and still display a different label:
Code: Select all
set the label of button "pay" to "Raise and invoice"
HTH
Stam
Re: Setting text into a button.
Did you script:CAsba wrote: ↑Wed Oct 05, 2022 1:58 pmI just enteredwithout successCode: Select all
... set the label of btn id 1006 to "Raise an invoice" ...
Code: Select all
on mouseup
set the label of btn id 1006 to "Raise an invoice"
end mouseup
If not "mouseup" where did you enter this?
Re: Setting text into a button.
I entered it into object > code
Re: Setting text into a button.
The code fragment as is has no trigger to make it run. Usually this will be a mouse action of some kind when it comes to buttons, but could equally be called in code from elsewhere.
But ultimately the app will need to know a user action that triggers this, eg mouseUp as Klaus showed, or could be for example mouseEnter, mouseLeave and so on.
Or run the command as is in the message box if you just want to test it.
But ultimately the app will need to know a user action that triggers this, eg mouseUp as Klaus showed, or could be for example mouseEnter, mouseLeave and so on.
Or run the command as is in the message box if you just want to test it.
Re: Setting text into a button.
The button where you want to set the label?
If yes, then you need to actually CLICK that button to execute that script.
If yes, then you need to actually CLICK that button to execute that script.
Re: Setting text into a button.
In the button’s script (object > code) you need to put a mouseUp handler so the button knows what to do when clicked.
Inside the mouseUp handler you run the code fragment posted above….
Klaus posted the full example above. It’s a rather basic thing that most of us take for granted now, but I remember forgetting to do this at the start.
Keep in mind the button can react to other events (like a rollover effect for example) so you need to tell the button what event to react to… hope that makes sense…
Inside the mouseUp handler you run the code fragment posted above….
Klaus posted the full example above. It’s a rather basic thing that most of us take for granted now, but I remember forgetting to do this at the start.
Keep in mind the button can react to other events (like a rollover effect for example) so you need to tell the button what event to react to… hope that makes sense…
Re: Setting text into a button.
Hi,
I selected mouseup handler, entered the code, came out of script and clicked the button.
Nothing happened, no text on button.
I selected mouseup handler, entered the code, came out of script and clicked the button.
Nothing happened, no text on button.
Re: Setting text into a button.
Is the button with the script the same button you want to set the label for?
Make sure the ID is correct, check the inspector.
However I highly recommend to give your button(s) meaningfull names!
Give the button you want to set the label for a NAME and try again.
Make sure the ID is correct, check the inspector.
However I highly recommend to give your button(s) meaningfull names!
Give the button you want to set the label for a NAME and try again.
Re: Setting text into a button.
CAsba.
Before steam starts coming out of the team here, open the attached stack. Clicking on the "Set Label" button will set the label of the lower left button to a random animal. You can see the handler in the "Set Label" button.
So it works, you see. The point is that somehow, somewhere in your own stack you are confusing LiveCode by using numbers as object references. DO NOT EVER DO THAT. LC has enough trouble keeping up with the several numbers it already assigns to each control without any of us adding to that burden.
If you do want to use numbers, and there are often very good reasons to do so, you have to couch them a little differently. For example, name your buttons "B1", B2" "B1006". That sort of thing, and then LC will not care, nor become confused.
Craig
Before steam starts coming out of the team here, open the attached stack. Clicking on the "Set Label" button will set the label of the lower left button to a random animal. You can see the handler in the "Set Label" button.
So it works, you see. The point is that somehow, somewhere in your own stack you are confusing LiveCode by using numbers as object references. DO NOT EVER DO THAT. LC has enough trouble keeping up with the several numbers it already assigns to each control without any of us adding to that burden.
If you do want to use numbers, and there are often very good reasons to do so, you have to couch them a little differently. For example, name your buttons "B1", B2" "B1006". That sort of thing, and then LC will not care, nor become confused.
Craig