OnEvent>DIALOG_CHANGE

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Fran D
Newbie
Posts: 15
Joined: Mon Aug 03, 2009 5:32 pm
Location: USA

OnEvent>DIALOG_CHANGE

Post by Fran D » Wed Aug 12, 2009 5:08 pm

I'm struggling a little with OnEvent...again...this time trying to understand how a dialog change is recognized.

I have two edit windows defined in a dialog as:

Edit=Site,x,y,z,0
Edit=Measurement,x,y,z,0

The idea is that when the user changes the value of 'Site', I will call a subroutine to rezero the value of 'Measurement'. I have in my loop,

OnEvent>DIALOG_CHANGE,DialogName,Site,ReZero

However, I never branch from here. I can change the value of Site and press Enter, tab to the next box, click somewhere else, yada yada, but this change is not being recognized.

What have I misconstrued about OnEvent>DIALOG_CHANGE?

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 12, 2009 6:38 pm

First any Onevent> only needs to be called once. Once it has been called it is active and cannot be made inactive except by closing your script. But that's a subject that has already been covered in the forum.

Second, you must be using a non-modal dialog for an Onevent> to function. If you have a Modal dialog, the script is paused waiting for user input. If the script is paused, it can't branch anywhere. A dialog is made Modal by placing the result variable on the Show> line

Show>DialogName,result

Is Modal

Show>DialogName

Is Non-Modal but requires more code to follow to gather the dialog results. See Dialog help for more detail.

Hope this is helpful. If not feel free to ask more questions. :)

Fran D
Newbie
Posts: 15
Joined: Mon Aug 03, 2009 5:32 pm
Location: USA

Post by Fran D » Wed Aug 12, 2009 8:07 pm

JRL wrote:First any Onevent> only needs to be called once. Once it has been called it is active and cannot be made inactive except by closing your script. But that's a subject that has already been covered in the forum.
Really? I thought it could reside in a loop. At least, I've put it there with several others, which are DIALOG_EVENT parameters and seem to be doing well.

Perhaps my question was too opaque without any code.

Code: Select all

Dialog>DataAcquisition
   Caption=DataAcquisition
   Width=704
   Height=290
   Top=104
   Left=16
   Label=Study Name,64,21,true
   Edit=StudyName,176,19,201,
   Label=Date,64,52,true
   Edit=Date,176,48,121,todaysdate
   Label=Operator,64,83,true
   Edit=Operator,176,77,121,
   Label=Panelist (1 - 999),64,131,true
   Edit=Panelist,240,127,56,1
   Label=Measurement Site (1 - 20),64,158,true
   Edit=Site,240,154,56,1
   Label=Measurement,64,185,true
   Edit=Measurement,240,181,56,1
   CheckBox=msCheckBox1,Check Box to Include Temperature && Humidity Data,64,224,400,False
   Button=Press Button for%CRLF%New Panelist,444,14,157,51,3
   Button=Press Button to%CRLF%Begin Measurements,444,80,157,51,4
   Button=Press Button to%CRLF%End,444,146,157,51,5
   Label=Use Footswitch to%CRLF%Trigger Data Collection,430,88,true
   Font=,11
EndDialog>DataAcquisition

Show>DataAcquisition

label>MeasurementLoop

  OnEvent>DIALOG_CHANGE,DataAcquisition,Panelist,ClearMeasures
  OnEvent>DIALOG_CHANGE,DataAcquisition,Site,ClearMeasures
  OnEvent>DIALOG_EVENT,DataAcquisition,4,HideBeginButton
  OnEvent>DIALOG_EVENT,DataAcquisition,3,RestoreBeginButton
  OnEvent>DIALOG_EVENT,DataAcquisition,5,Exit
  OnEvent>KEY_DOWN,VK32,0,MeasureApps

goto>MeasurementLoop
The OnEvents for the DIALOG_EVENT & KEY_DOWN are working like a charm. It's just the DIALOG_CHANGE that are dead. Maybe it's the sub that's screwed?

Code: Select all

SRT>ClearMeasures
  Let>DataAcquisition.Measurement=1
  ResetDialogAction>DataAcquisition
END>ClearMeasures
Thoughts?

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 12, 2009 9:02 pm

This is complicated and I don't have time right now to give you a proper answer. However, as I said before, move the OnEvents out of the loop up to the top of the script. I understand that they are working from the loop but I'm concerned there might be memory issues if they get called hundreds of times per second.

I tested your code and the OnEvents are working as advertised. the problem is you are resetting the dialog without resetting the value of the edit boxes. Put a MessageModal> in the "ClearMeasures" subroutine and you'll see what I mean. Or delete the "1" that is predefined in the "Measurement" Edit box and change one of the other edit boxes and a "1" will return as the subroutine requests.

The other (complicated) half of theis problem is that using the "DIALOG_CHANGE" OnEvent> to detect a change in the edit field will mean that OnEvent will fire your subroutine every time any character changes in the edit field. For example: You have a "1" in there to start. If you press "delete" to remove the "1" the OnEvent will fire. When you press a "9" the OnEvent will fire. When you press another "9" the OnEvent> will fire. Etc. Consequently, your subroutine needs to somehow detect that a new number has been completely typed into the edit field before it performs the "measurement" edit field update. It also needs to perform a GetDialogAction to reset the dialog variable values prior to running the ResetDialogAction otherwise the edit field values that are typed will never update.

Fran D
Newbie
Posts: 15
Joined: Mon Aug 03, 2009 5:32 pm
Location: USA

Post by Fran D » Wed Aug 12, 2009 10:11 pm

I appreciate all the help you've given. I think I can begin to see what I've done wrong and, perhaps, effect a workaround that still gets me to where I need to be.

I have to admit, though, that I was a bit horrified to hear that the OnEvents could not exist in a loop. Especially with how well the bulk of the script was working! I did open up Task Manager and watch to see if there were any memory, thread or handle leaks while I just continuously bopped through the loop. Nothing appeared to continuously grow with the firing of any of the OnEvents. I don't know if that means anything or not.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Aug 13, 2009 9:50 am

It won't matter whether OnEvent is in the loop or outside of it. However, putting it inside a loop is pointless. Once it's set, it's set. It doesn't need constant resetting. Having it inside a loop is just wasteful.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Fran D
Newbie
Posts: 15
Joined: Mon Aug 03, 2009 5:32 pm
Location: USA

Post by Fran D » Thu Aug 13, 2009 11:19 am

Yeah, I think I can see that now. My big concern was trying to reuse the OnEvent since its functionality is exactly what I'm looking for in the script. I'll rewrite the script to move the OnEvevnts out of the loop and institute an idler loop that I can bang in and out of to keep the script running. Since I'm toggling the OnEvent with the DAILOG_EVENT parameters, perhaps the reuse is already there? I'll give it a shot.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts