cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically change Text in a Button

Former Member
0 Kudos

I am trying to learn DS.  I want to know how I would change the text on a Button to the current date.  I searched and could not find any examples.  Can someone tell me how I would do this?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

TammyPowlas
Active Contributor
0 Kudos

Look at this thread How to display "current date -1" means yesterda... | SCN

application.getinfo method as mentioned in this thread - please try that and see if it meets your needs.

Former Member
0 Kudos

I think I need to add the code below to set the text for BUTTON_1 to the current date but I do not know where to put this code

currmonth = APPLICATION.getinfo().dateNowInternalFormat.substring(0,6);

BUTTON_1.setText(currmonth).

Any help is appreciated.

Thanks.

Sandy

Former Member
0 Kudos

Hi Sandy

If you want to set the text in the button in the initial. you can write the code in the event "On startup".

How to find the startup.

1.Click the Application layer in the outline.

2. In the properties, you can find "On startup"  in  the "Event" section.

If you want to write the code which is interactive.

Write the code in the "On click" which in the each component' properties.

Hope this help.

Willy

Former Member
0 Kudos

Hi Sandy ,

why do you need to two line of script just try this code in Application On Startup script:


BUTTON_1.setText(APPLICATION.getInfo().dateNow);

Once your Run the Application the button text will get change to current data .

Hope this might help

Thanks

Naveen

Answers (1)

Answers (1)

david_stocker
Advisor
Advisor
0 Kudos

I'd not regard setting the text in the application startup script to be a best practice.  A year from now, you'll have the app open for tweaking and you'll have forgotten where you were setting the date.

Set data minding on the button's text property and use a formatter function to set the text.  It's cleaner this way.

david_stocker
Advisor
Advisor
0 Kudos

*data binding... not data minding.

Former Member
0 Kudos

Hi David,

Being new to DS, I do not understand how to implement your solution.  In DS, I did the following:

1. Displayed Properties for Text object

2. With cursor on Text, I selected Data Cell Binding

What do I select for Data Source and Selected Data Cell and Formatter Function

Sandy

Former Member
0 Kudos

Hi David,

I figured out how to do this.  Thank you for the suggestion.  It is very helpful to me as a learner to learn about the different options available in DS.

Regards,

Sandy

david_stocker
Advisor
Advisor
0 Kudos

I probably should have explained how to do it, I just did not have DS open for reference at the time.  I'm glad you got the hand of it.  Formatter functions allow you to greatly simplify the architecture of your apps.