How do you use a Dialog_Change OnEvent>?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

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

How do you use a Dialog_Change OnEvent>?

Post by JRL » Mon Jan 24, 2011 2:28 pm

We have dialogs we've created to collect bar coded data on the shop floor. The bar codes contain two trigger characters "$%" that we want to strip off in the edit field so that the operators don't have to see them. Prior to version 12 we did this in the action loop by testing the contents of the edit field and stripping out the trigger characters. Of course, this required the use of GetDialogAction> which no longer works in an action loop.

We have been trying to figure out how to use the Dialog_Change OnEvent>. Help for OnEvent> states:
DIALOG_CHANGE

EventParm is the dialog name. ExtraParm is the object name. When the value of the object is changed by the user the subroutine is triggered. Valid object types include Edit, Memo, ComboBox, ListBox, RadioGroup and CheckBox
Sounds like exactly what we want. But we can't figure out how t make it work. We've tried both modal and non-modal dialogs and tried placing a
GetDialogProperty> in the non-modal loop thinking that perhaps that was needed to set the edit box value for the onEvent to trigger. No luck.

Following is a sample of what we've been trying to do. It seem to me that the "FixIt" subroutine should be triggered as soon as any character is typed into the edit field. I do not get the subroutine to run no matter what I try.

Any ideas?

Code: Select all

OnEvent>Key_Down,VK27,0,Quit
OnEvent>DIALOG_CHANGE,dialog1,Edit1,FixIt

SRT>FixIt
  MDL>Ok
  GetDialogProperty>dialog1,Edit1,Test,txtseq1
  StringReplace>txtseq1,$,,txtseq1
  StringReplace>txtseq1,%,,txtseq1
  SetDialogProperty>dialog1,Edit1,Test,txtseq1
END>FixIt

Dialog>Dialog1
object Dialog1: TForm
  Left = 501
  Top = 219
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 223
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 90
    Top = 55
    Width = 247
    Height = 21
    TabOrder = 0
    Text = ''
  end
end
EndDialog>Dialog1
AddDialogHandler>dialog1,,onclose,Quit

Show>dialog1
//Show>dialog1,res1

Label>Loop
  Wait>0.01
  //GetDialogProperty>dialog1,Edit1,Test,txtseq1
Goto>Loop

SRT>Quit
  Exit>
END>Quit

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

Post by Marcus Tettmar » Mon Jan 24, 2011 3:08 pm

Don't.

The Dialog_Change onEvent was provided pre v12 before we had dialog event handlers.

With v12 just use the edit's OnChange event handler with AddDialogHandler.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Mon Jan 24, 2011 3:12 pm

Thanks for the response. We'll give it a try.

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

Post by JRL » Mon Jan 24, 2011 3:28 pm

Yes!... that did work. I'll post a working example when I get time.

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

Post by JRL » Mon Jan 24, 2011 6:26 pm

Yes, it works and here is a working example: (please continue reading after the sample)

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 511
  Top = 187
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 223
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 90
    Top = 55
    Width = 247
    Height = 21
    TabOrder = 0
  end
  object Edit2: TEdit
    Left = 91
    Top = 86
    Width = 246
    Height = 21
    TabOrder = 9
  end
end
EndDialog>Dialog1
AddDialogHandler>dialog1,,onclose,Quit
AddDialogHandler>dialog1,edit1,onchange,FixIt1
AddDialogHandler>dialog1,edit2,onchange,FixIt2

Show>dialog1,res1

SRT>FixIt1
  GetDialogProperty>dialog1,Edit1,Text,txtseq1
  StringReplace>txtseq1,$,,txtseq1
  StringReplace>txtseq1,%,,txtseq1
  SetDialogProperty>dialog1,Edit1,Text,txtseq1
END>FixIt1

SRT>FixIt2
  //GetFocusedObject>FocOb
  //MDL>FocOb
  GetDialogProperty>dialog1,Edit2,Text,txtseq1
  StringReplace>txtseq1,$,,txtseq1
  StringReplace>txtseq1,%,,txtseq1
  SetDialogProperty>dialog1,Edit2,Text,txtseq1
END>FixIt2

SRT>Quit
  Exit>
END>Quit
BUT, If you look at this you'll notice there is a subroutine for each edit box. If you have 20 edit boxes, it would seem, you'll need 20 subroutines. Is there any way to recognize which edit box is focused and pass that info to a single subroutine?

I tried using GetFocusedObject> but it doesn't seem to work on a Macro Scheduler dialog. It also occurred to me to try to place an extra parameter at the end of the AddDialogHandler> line. But, though that does not produce an error, it will actually cause the script to start again at line one. So that is not an option.

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

Post by Marcus Tettmar » Mon Jan 24, 2011 8:07 pm

Like this:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 511
  Top = 187
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 223
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 90
    Top = 55
    Width = 247
    Height = 21
    TabOrder = 0
  end
  object Edit2: TEdit
    Left = 91
    Top = 86
    Width = 246
    Height = 21
    TabOrder = 9
  end
end
EndDialog>Dialog1
AddDialogHandler>dialog1,,onclose,Quit
AddDialogHandler>dialog1,edit1,onchange,FixIt(Edit1)
AddDialogHandler>dialog1,edit2,onchange,FixIt(Edit2)

Show>dialog1,res1

SRT>FixIt
  GetDialogProperty>dialog1,FixIt_Var_1,Text,txtseq1
  StringReplace>txtseq1,$,,txtseq1
  StringReplace>txtseq1,%,,txtseq1
  SetDialogProperty>dialog1,FixIt_Var_1,Text,txtseq1
END>FixIt

SRT>Quit
  Exit>
END>Quit
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by JRL » Tue Jan 25, 2011 3:19 pm

Thanks Marcus. Guess I should have read the documentation. Sorry. Pressed for time and asking was easier than reading.

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