What I am trying to do is create a loop that looks at a MS Dialog Box and determines which text box has the cursor in it. (sort of like what window has the focus, only what text box has it)
What I am going to be doing with it is scaning numerous barcodes into a dialog. Once scanned or manually entered it will proceed to the next text box. Before data can be entered into the next text box the data in the previous one will be validated. So, I need to determine which box the cursor is in. Once deteremined, I can validate the previous box, if it passes fine, if not I will have an error tone play and then move it back to the box it should be in.
Then there is the part just mentioned, how do I move the cursor to a specific box? For instance, once all the boxes are filled I want to double check them and if one has an impropper value I want to place the cursor back in the box that needs to be rescanned. (this would be similar to the SetFocus command if I was looking at windows instead of a text box in a MS Dialog)
Determining which text box has focus
Moderators: JRL, Dorian (MJT support)
Tab through or enter
I found another way to do this. But I am still sort of stuck on one part. Is there a way where when someone is done entering text into a text box and they press enter it will move to the next text box. In other words, it does what I want if I press tab but I would like to have the option of pressing enter.
Below is the sample code so far
AddDialogHandler>Dialog1,Edit1,OnExit,check1
Show>Dialog1,r
If>r=2
Goto>Endofit
Endif
SRT>check1
GetDialogProperty>Dialog1,Edit1,text,tt
// Change this later to validate with EasyPattern - currently it just looks for a match of 1111
If>tt=1111
PlayWav>c:\windows\media\Windows User Account Control.wav
SetDialogObjectFocus>Dialog1,Edit2
Goto>End_of_check_1
Else
PlayWav>Speech Sleep.wav
SetDialogProperty>Dialog1,Edit1,text,
SetDialogObjectFocus>Dialog1,Edit1
Endif
Label>End_of_check_1
END>check1
Label>Endofit
Below is the sample code so far
AddDialogHandler>Dialog1,Edit1,OnExit,check1
Show>Dialog1,r
If>r=2
Goto>Endofit
Endif
SRT>check1
GetDialogProperty>Dialog1,Edit1,text,tt
// Change this later to validate with EasyPattern - currently it just looks for a match of 1111
If>tt=1111
PlayWav>c:\windows\media\Windows User Account Control.wav
SetDialogObjectFocus>Dialog1,Edit2
Goto>End_of_check_1
Else
PlayWav>Speech Sleep.wav
SetDialogProperty>Dialog1,Edit1,text,
SetDialogObjectFocus>Dialog1,Edit1
Endif
Label>End_of_check_1
END>check1
Label>Endofit
Is this what you're looking for?
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 510
Top = 167
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 224
ClientWidth = 265
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 Label1: TLabel
Left = 8
Top = 8
Width = 49
Height = 13
Caption = 'Barcode 1'
end
object Label2: TLabel
Left = 8
Top = 48
Width = 49
Height = 13
Caption = 'Barcode 2'
end
object Label3: TLabel
Left = 8
Top = 88
Width = 49
Height = 13
Caption = 'Barcode 3'
end
object Label4: TLabel
Left = 8
Top = 128
Width = 49
Height = 13
Caption = 'Barcode 4'
end
object Edit1: TEdit
Left = 8
Top = 24
Width = 145
Height = 21
TabOrder = 0
end
object Edit2: TEdit
Left = 8
Top = 64
Width = 145
Height = 21
TabOrder = 1
end
object Edit3: TEdit
Left = 8
Top = 104
Width = 145
Height = 21
TabOrder = 2
end
object Edit4: TEdit
Left = 8
Top = 144
Width = 145
Height = 21
TabOrder = 3
end
object MSButton1: tMSButton
Left = 8
Top = 184
Width = 75
Height = 25
Caption = 'Submit'
TabOrder = 4
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,Edit1,OnKeyDown,CheckIfEnterKeyPressed(1)
AddDialogHandler>Dialog1,Edit2,OnKeyDown,CheckIfEnterKeyPressed(2)
AddDialogHandler>Dialog1,Edit3,OnKeyDown,CheckIfEnterKeyPressed(3)
AddDialogHandler>Dialog1,Edit4,OnKeyDown,CheckIfEnterKeyPressed(4)
Show>Dialog1,r
SRT>CheckIfEnterKeyPressed
//Virtual key code 13 = Enter Key pressed
IF>CheckIfEnterKeyPressed_Key=13
Let>EditBoxNum=%CheckIfEnterKeyPressed_Var_1%
Add>EditBoxNum,1
IF>EditBoxNum=5
//Focus submit button
SetDialogObjectFocus>Dialog1,MSButton1
ELSE
//Set focus to next edit box
SetDialogObjectFocus>Dialog1,Edit%EditBoxNum%
ENDIF
ENDIF
END>CheckIfEnterKeyPressed
Hi Keith,
Here's how I would do it. Did not include your chimes and stuff but you'll get the general idea.
I think you could do a Shift Enter too but it gets more complicated to do it correctly and I think it would need to be a non-modal dialog. If you need it let me know and I'll work on it at lunch.
Edit:
Hmmm. I see Rain beat me to the punchline by a few minutes. We have slightly differing methods so you now have a couple of new ideas to test.
Here's how I would do it. Did not include your chimes and stuff but you'll get the general idea.
I think you could do a Shift Enter too but it gets more complicated to do it correctly and I think it would need to be a non-modal dialog. If you need it let me know and I'll work on it at lunch.
Edit:
Hmmm. I see Rain beat me to the punchline by a few minutes. We have slightly differing methods so you now have a couple of new ideas to test.
Code: Select all
OnEvent>key_down,VK13,0,EnterKey
Dialog>Dialog1
object Dialog1: TForm
Left = 312
Top = 189
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Dialog For Keith'
ClientHeight = 223
ClientWidth = 484
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 Label1: TLabel
Left = 272
Top = 96
Width = 32
Height = 13
Caption = 'Label1'
end
object Edit1: TEdit
Left = 66
Top = 38
Width = 121
Height = 21
TabOrder = 0
Text = 'Edit1'
end
object Edit2: TEdit
Left = 67
Top = 72
Width = 121
Height = 21
TabOrder = 1
Text = 'Edit2'
end
object Edit3: TEdit
Left = 68
Top = 101
Width = 121
Height = 21
TabOrder = 2
Text = 'Edit3'
end
object Edit4: TEdit
Left = 72
Top = 134
Width = 121
Height = 21
TabOrder = 3
Text = 'Edit4'
end
object Edit5: TEdit
Left = 72
Top = 166
Width = 121
Height = 21
TabOrder = 4
Text = 'Edit5'
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,Edit1,OnEnter,WhichField(1)
AddDialogHandler>Dialog1,Edit2,OnEnter,WhichField(2)
AddDialogHandler>Dialog1,Edit3,OnEnter,WhichField(3)
AddDialogHandler>Dialog1,Edit4,OnEnter,WhichField(4)
AddDialogHandler>Dialog1,Edit5,OnEnter,WhichField(5)
Show>Dialog1,
SRT>WhichField
SetDialogProperty>Dialog1,Label1,Caption,Cursor is in Edit%WhichField_var_1%
END>WhichField
SRT>EnterKey
GetActiveWindow>AWTitle,AWWinX,AWWinY
If>AWTitle=Dialog For Keith
SetFocus>Dialog For Keith
Press Tab
Wait>0.2
EndIf
END>EnterKey
Perfect
Thanks guys I just tested them both and they both work great. Now it is just a matter of which way to go.
I'm thinking the tab or/and enter, confirm after each and play noise, then either lock the value and proceed to the next or wait until all are entered double check the values before submitting.
It just has to be simple for the user and as idiot proof as it can get. I mean real idiot proof.
I'm thinking the tab or/and enter, confirm after each and play noise, then either lock the value and proceed to the next or wait until all are entered double check the values before submitting.
It just has to be simple for the user and as idiot proof as it can get. I mean real idiot proof.