cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How to initialize a push button

Raiko
17-Peridot

How to initialize a push button

Hello all MCers,

I have a worksheet in MC14 with ten (10) push buttons. Before you ask - yes, I need all of them.
According to each button's state (+1 or -1) different codes are executed. However, I noticed that the push buttons have to be pushed (sometimes) several times before they yield the proper state. Upon start some are set to zero and remain at that condition unless I push them with increasing desperation. I therefore need means to initialize the button. I've tried to define the state in the script (event.start section) but this merely "freezes" the state.
Does anybody has an idea how I either initialize properly a push button (to say, +1) or how to convince MC that one push should be enough to toggle between states?

Thanks in advance

Raiko
9 REPLIES 9

I think better to use not buttons but check boxes - we see a status of check box!

Try please:
http://twtmas.mpei.ac.ru/mas/Worksheets/Hydro/Turb_Oil.mcd
Val
http://twt.mpei.ac.ru/ochkov/v_ochkov.htm

Hello Valerij,

thank you for your contribution. However, I've chosen a push button as I can display the changed state (+) or (-) on the button when it is clicked. This information is crucial therefore push buttons

Raiko
TomGutman
1-Visitor
(To:Raiko)

NO idea what you've done. The standard script that drives the pushbutton causes a state change at each click. If you are not getting that, you have probably changed the script incorrectly.

If you've even been thinking of doing initialization in the event_start routine you clearly don't understand how the script works, and when sections of it get executed. The event_start and event_stop routines are useless (information from Mathsoft) and get executed each time the control is evaluated.
__________________
� � � � Tom Gutman
Raiko
17-Peridot
(To:TomGutman)

On 7/8/2009 4:51:54 AM, Tom_Gutman wrote:
>NO idea what you've done. The
>standard script that drives
>the pushbutton causes a state
>change at each click. If you
>are not getting that, you have
>probably changed the script
>incorrectly.
>
>If you've even been thinking
>of doing initialization in the
>event_start routine you
>clearly don't understand how
>the script works, and when
>sections of it get executed.
>The event_start and event_stop
>routines are useless
>(information from Mathsoft)
>and get executed each time the
>control is evaluated.
>__________________
>� � � � Tom Gutman


Hello Tom,

what I've done is simple: I added a line that decides upon the button state to label said button accordingly; see below:

< sub pushbtn_click()
< if state=-1 then
< state=1
< pushbtn.text="+"
< else
< state=1
< pushbtn.text="-"
< end if
< pushbtn.recalculate()
< end sub

Looks pretty straight forward to me.
However, as I said before: somewtimes a button doesn't change state when pushed. Useless or not, means to "initialize" the push button would help me.
Do you have any suggestions what might be wrong with the code?

Thanks

Raiko
RichardJ
19-Tanzanite
(To:Raiko)

To save us retyping stuff, and possibly doing so in a way that is slightly different to what you have done, could you post a worksheet with one of these buttons.

Richard
Raiko
17-Peridot
(To:RichardJ)

On 7/8/2009 9:08:52 AM, rijackson wrote:
>To save us retyping stuff, and
>possibly doing so in a way
>that is slightly different to
>what you have done, could you
>post a worksheet with one of
>these buttons.
>
>Richard



Hello Richard,
here we go.
As visible in the array "q" on the right hand side, not all outputs of the buttons are defined - which makes it necessary to click all of them in order to get the scripts executed.
Raiko
RichardJ
19-Tanzanite
(To:Raiko)

When you launch the Mathcad worksheet the PushBtn_Click() subroutine is not executed. So the variable state is dimensioned, but since nothing is done to assign it any value it just has the default value of 0. Since no text is assigned to the push button, the text is whatever was there the last time you saved the Mathcad worksheet (it's stored internally). The first time you click on a button state is not equal to -1, so the else cause is executed, which sets the state to -1 and the text to "-". If the text was already set to "-" when the worksheet was loaded the button may appear to have not executed, but it did, and the corresponding value in q changes to -1. To fix this behaior, immediately after the statement Dim state add two more lines:

state = 1
PushBtn.Text = " + "

These are in the body of the script, outside of any subroutines. They will be executed when the worksheet is loaded, but only then. In the above example the state will be set to 1, and the text to " + ".

Richard
Raiko
17-Peridot
(To:RichardJ)

Hello Richard, Hello Tom,

thank you both very much. That was what I was looking for.

Raiko
TomGutman
1-Visitor
(To:Raiko)

As Richard says, you just didn't do the initialization. Note that the standard push button alternates between zero and one, so the default initialization of zero is appropriate. When you changed to alternate between plus and minus one you needed to change that.

Here is a box that initializes to its last saved state (rather than a fixed +). And note that check boxes can have variable text, and can also look much like pushbuttons.
__________________
� � � � Tom Gutman
Announcements

Top Tags