WinBatch® Technical Support Forum

Archived Boards => WinBatch Dynamic Dialogs => Topic started by: vavery on November 09, 2015, 02:09:50 PM

Title: Close Dialog on Enter in Editbox
Post by: vavery on November 09, 2015, 02:09:50 PM
I want to create a dialog with some variable text and static text and one edit box.  I will be scanning data into the editbox with a barcode scanner that will append a CRLF at the end data string  Is there a way to close the dialog box without pressing a button?  I'd like the CRLF to trigger closing the dialog.  I appreciate any advice that can be offered.
Title: Re: Close Dialog on Enter in Editbox
Post by: td on November 09, 2015, 03:19:06 PM
Depending on what you mean by 'scanning' that could happen by default if you have  a visible default button on the dialog.  Otherwise, you will need to setup a user defined dialog callback procedure and have it monitor the @deEdText event.  When the event occurs you can check the edit box's text for the presents of the appropriate characters and terminate the dialog by having the your procedure return a positive number. 
Title: Re: Close Dialog on Enter in Editbox
Post by: JTaylor on November 09, 2015, 03:24:11 PM
Yes.  Give the "Default" button option a try as Tony suggests.  That should do what you want.

Jim
Title: Re: Close Dialog on Enter in Editbox
Post by: vavery on November 09, 2015, 03:31:50 PM
Thank you Tony and Jim.  I basically want to continuously type a 10 digit number, hit enter, filewrite the string, reopen dialog and repeat.  So hopefully the default button will work as I haven't had a lot of luck with the user defined functions yet.  Thanks again for the advice.
Title: Re: Close Dialog on Enter in Editbox
Post by: vavery on November 11, 2015, 12:51:11 PM
I'm looking at the callback procedure now, but I need to start the dialog and have the cursor sitting in the editbox ready to take input and then close the dialog when Enter or CRLF is detected. 
Title: Re: Close Dialog on Enter in Editbox
Post by: vavery on November 11, 2015, 01:16:23 PM
I guess I'm going to have to just use Askline to do this program even though it will not look as nice.  I'm under a time crunch to make this work, so I'll do that and then figure out how to make it look the way I want and with larger fonts using the dialog callback.
Title: Re: Close Dialog on Enter in Editbox
Post by: JTaylor on November 11, 2015, 01:30:37 PM
Not sure what you want from us?   If you create the dialog and set the editbox tab order as 1 and the others greater than 1 then things should start in the editbox without having to tell it to go there within the program.

If you set the Style for the OK button to "Default" when you send the @CRLF from the scanner it should activate the OK button.

Not sure why you want it to close every time if you are scanning a bunch of items.  If you are using the callback then you wouldn't want that behavior but that is a bit more involved than just using the dialog without a callback.

If just using the dialog then it would close when you click a PushButton so just need it in the loop.

Jim
Title: Re: Close Dialog on Enter in Editbox
Post by: JTaylor on November 11, 2015, 01:41:55 PM
Here is a CallBack Example:

Code (winbatch) Select


[font=courier]
Home_Path = DirScript()
Data_Path = ShortCutDir("Local AppData",0,@TRUE):"Scan\"
DirChange(Home_Path)
GoSub Load_Routines
IntControl(49,3,0,0,0)

ScanFormat=`WWWDLGED,6.2`

ScanCaption=`Scan`
ScanX=-01
ScanY=-01
ScanWidth=144
ScanHeight=057
ScanNumControls=004
ScanProcedure=`Scan`
ScanFont=`DEFAULT`
ScanTextColor=`DEFAULT`
ScanBackground=`DEFAULT,192|192|192`
ScanConfig=0

Scan001=`047,037,036,012,PUSHBUTTON,pb_Sca_OK,DEFAULT,"OK",1,2,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
Scan002=`097,037,036,012,PUSHBUTTON,pb_Sca_Cancel,DEFAULT,"Cancel",0,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Scan003=`023,007,112,012,EDITBOX,eb_Sca_scan_text,scan_text,"scan_text",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Scan004=`001,009,020,012,STATICTEXT,st_Sca_Text,DEFAULT,"Text:",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`


ButtonPushed=Dialog("Scan")


Exit

:Load_Routines
   

#DefineSubRoutine Scan(Sca_Handle,DMsg,DCID,DEInfo,ChangeInfo)

Switch (DMsg)
    Case @deInit

    DialogProcOptions(Sca_Handle, @deClose,1)                             ; Close selected (IntControl(49....) (1-On, 0-Off).
    DialogProcOptions(Sca_Handle, @dpoDisable,0)                          ; Dialog Disable (1-Disable, 2-Wait cursor, 0-Enable).
    DialogProcOptions(Sca_Handle, @dpoBkground,-1)                        ; Change Dialog Background (Bitmap File or RGB String).
    DialogProcOptions(Sca_Handle, @dePbPush,1)                            ; Pushbutton/PictureButton.
    DialogProcOptions(Sca_Handle, @deEdText,1)                            ; EditBox or Multi-LineBox.
   
    scan_text = ""
    DialogControlSet(Sca_Handle,"eb_Sca_scan_text",@dcText,scan_text)
    DialogControlState(Sca_Handle,"eb_Sca_scan_text",@dcsSetFocus,1)
   
    Break
  Case @deClose
    Return 9
    Break
  Case @deEdText
    Switch(DialogProcOptions(Sca_Handle,@dpoCtlNumber,DCID))
      Case DialogProcOptions(Sca_Handle,@dpoCtlNumber,"eb_Sca_scan_text")
        scan_text = DialogControlGet(Sca_Handle,"eb_Sca_scan_text",@dcText)
        Break
    EndSwitch
    Break
  Case @dePbPush
    Switch(DialogProcOptions(Sca_Handle,@dpoCtlNumber,DCID))
      Case DialogProcOptions(Sca_Handle,@dpoCtlNumber,"pb_Sca_OK")
        scan_text = DialogControlGet(Sca_Handle,"eb_Sca_scan_text",@dcText)

;###########################
Message("SCAN",scan_text)
;DO WHATEVER WITH THE DATA
;###########################

        scan_text = ""
        DialogControlSet(Sca_Handle,"eb_Sca_scan_text",@dcText,scan_text)
        DialogControlState(Sca_Handle,"eb_Sca_scan_text",@dcsSetFocus,1)
     
        Break
      Case DialogProcOptions(Sca_Handle,@dpoCtlNumber,"pb_Sca_Cancel")

;###########################
;DO WHATEVER BEFORE CLOSING
;###########################

        Return -1
        Break
    EndSwitch
    Break
EndSwitch
Return -2

#EndSubRoutine
 

Return[/font]

Title: Re: Close Dialog on Enter in Editbox
Post by: vavery on November 11, 2015, 08:12:06 PM
Jim,
Wow.  I appreciate this sample code.  My main objective was to be able to keep reading barcodes without any user intervention via mouse or keyboard.  I was able to display the additional info, number of scans, last scans using the AskLine command, but I was limited to 4 lines of text above the input line.  I also thought I had the tab order correct, but apparently I did not because I did as you suggested and created a new dialog and made sure my editbox was first in the tab order and then it seemed to work.  So your original suggestion indeed works.  I probably messed up because I had originally removed the OK button and then added it back.  Also I was closing the dialog box because I don't know how to keep the dialog open and have Winbatch do something in the background.  Although obviously the answer is in the Callback Dialog, as soon as I can fully understand it.  I would just collect the data string, close, make sure its 10 characters, append the data to a file named current date and then repeat dialog.  I've written several scripts in Winbatch over the years just nothing complex enough to need to be interactive.

Now I also realized my real problem was that I decided to use group boxes to separate the info showing scan count, last scan from the scan field.  So if I could read, I would have seen this:  "The Group Box control owns all the controls inside of it and it tends to use the tab order of the Group Box". 

So after all that,  THANK YOU!  THANK YOU!

Virgil