Help with Method please

I am working through a tutorial at the moment and building a Calculator. To get the buttons from 1 to 0 I am supposed to add a method to toggle these buttons to place the digits within a read only text field using the following:

For starters, add the following code statement to the method belonging to each of the
PushButton controls that represents a numeric calculator button, as well as to the button representing a toggle value (for example, the PushButtons labeled 0–9 and -).

OutputField.Text = OutputField.Text + Me.Caption

This statement, when executed, adds the number of the appropriate PushButton control
to the EditField control. For example, if the user clicks the PushButton control representing the
number 5, this statement takes the value of that PushButton control’s Caption (for example 5),
which it gets from Me.Caption, and appends it to whatever text is currently displayed in the
EditField control.<<

I have placed the code in the action method but nothing happens, which method should I be using please?

Many thanks for any/all input
Graham

When you say “Action Method”, you mean you added an Action event handler?
If so, this would be ok so the error should be somewhere else. Would you mind showing more of your code or even upload your project?

Thanks for getting back Ulrich, appreciated.

Yes, method added to the action method.

Here is a link to the calculator application:

https://1drv.ms/u/s!AsX2rxZnJcf_bfNZl7ngZVo4U5c

Thanks again
Graham

Hi Graham,

in your project I can find neither action method nor action event handler and nothing that addresses the output field.
Are you sure you sent the current stage of your project?

Anyway, the way to add the code would be to
– Select one of the buttons and
– Rightclick on it (or use the “Add” symbol in the tool bar) and select “Event handler”.
– From the popup, select “Action” and then enter the code like you wrote above.

There is something fishy with your textfield. It did not want to show text unless it was clicked. I could not figure out what and simply replaced it with a fresh textfield, duplicating your properties (right alignment, read-only, 18 ptr text). Did Xojo crash or did you try to subclass the textfield or change its inspector behavior?

If you want it easier, you can group all relevant buttons into a control set:
– Select all buttons for which the action event should apply (all but not “Off” and “Clear”)
– Switch to the second tab of the Inspector (the one with the gear icon) and select “New control set”
They are then grouped and you will find a parent icon named “members”. Select this one and add the action event with the same code:

OutputField.text = OutputField.text + me.Caption

This enables the event for all buttons at once. And of course set the default window in your app object to MainWindow1. Your project arrived without a default window, so it showed only the Menu bar when started.

Ah, on reflection I think I sent a previous write of the application through. My apologies for this :frowning:

Your write-up is very welcomed and will help alot.

Sincere thanks for your time
Graham

You’re welcome, Graham! if it doesn’t work for you, send me your mail address privately and I’ll mail you the fixed project. ( A shame the public dropbox folder does not work anymore …)