WinBatch® Technical Support Forum

Archived Boards => WinBatch Dynamic Dialogs => Topic started by: seckner on October 01, 2013, 02:27:41 PM

Title: Filling an edit box from a drop list
Post by: seckner on October 01, 2013, 02:27:41 PM
Sorry, don't work with dialog's much and it shows. I'm reading 2 text files into strings. On my dialog I want to have the user select a value from a DropList populated by the first string - this is  done and works fine. The problem I'm having is, once item 2 is selected I'd like to display item 2 from the second string in an edit box. So, since I don't explain well:

string 1 = a, b, c, d, e 
string 2 = m, n, o, p, q  (both delimited with tabs)
If the user selects 'b" from the drop down, I want the edit box to display "n"
I know the mechanics of doing the selection but I don't understand how to get it into the edit box.   

I found a script in the database that uses two item boxes - but the edit box won't accept an item insert.  Ideas VERY welcome! 
Title: Re: Filling an edit box from a drop list
Post by: DAG_P6 on October 02, 2013, 06:05:48 AM
The edit box in your dialog box is defined by a line of code that looks like the following.
StrLenCalc02 = `65,10,210,DEFAULT,EDITBOX,InputString,""`

In the statement shown above, InputString is the name of a variable that contains the text shown in the edit control. Assign the value returned by the list box to it.
Title: Re: Filling an edit box from a drop list
Post by: Deana on October 02, 2013, 08:31:10 AM
If I understand, you have two correlated lists. You would like to update an EDITBOX control dynamically when an item is selected from the DROPLISTBOX. If so you are going to need a Dynamic Dialog that uses a Dialog Callback Procedure to handle the DROPLISTBOX/Combobox event. In the event handler for the DROPLISTBOX you can get the selected item. Use ItemLocate to locate the items position in the list. Now that you have the position you can extract the item from your second list at the SAME position, then update the EDITBOX control.

Here is a code sample:

Code (winbatch) Select

#DefineSubroutine MyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_Name,MyDialog_EventInfo,MyDialog_ChangeInfo)
   MSG_INIT=0                    ; The one-time initialization
   MSG_BUTTONPUSHED=2            ; Pushbutton or Picturebutton
   MSG_EDITBOX=5                 ; Editbox or Multilinebox
   MSG_COMBOCHANGE=8             ; Combobox/Droplistbox
   DC_EDITBOX=3                  ; EDITBOX MULTILINEBOX
   DC_ITEMBOXSELECT=6
   ;Return code constants
   RET_DO_CANCEL=0           ; Cancels dialog
   RET_DO_DEFAULT= -1        ; Continue with default processing for control
   RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
   ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
   switch MyDialog_Message                                  ; Switch based on Dialog Message type
      case MSG_INIT                                         ; Standard Initialization message
;         DialogProcOptions(MyDialog_Handle,MSG_TIMER,1000)
         DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(MyDialog_Handle,MSG_EDITBOX,@TRUE)
         DialogProcOptions(MyDialog_Handle,MSG_COMBOCHANGE,@TRUE)
         return(RET_DO_DEFAULT)

     case MSG_BUTTONPUSHED
        if MyDialog_Name == "PushButton_OK"                ; OK
              return(RET_DO_DEFAULT)

        elseif MyDialog_Name == "PushButton_Cancel"        ; Cancel
              return(RET_DO_DEFAULT)

        endif                                              ; MyDialog_Name
        return(RET_DO_DEFAULT)

;     case MSG_EDITBOX                                      ; ID "EditBox_1"  ebVariable1
;        return(RET_DO_DEFAULT)

     case MSG_COMBOCHANGE                                  ; ID "DropListBox_1"  dlVariable1
        ;Get selected item
        dlItem = DialogControlGet( MyDialog_Handle, "DropListBox_1", DC_ITEMBOXSELECT, 0 )
        ;Now locate that items position in the list
        pos = ItemLocate( dlItem, string1, @tab )
        ;Grab the value at the SAME osition in the second list
        editvalue = ItemExtract( pos, string2, @tab )
        ;Now update edit box
        DialogControlSet( MyDialog_Handle, "EditBox_1", DC_EDITBOX, editvalue )
        return(RET_DO_DEFAULT)

   endswitch                                                ; MyDialog_Message
   return(RET_DO_DEFAULT)
#EndSubroutine                                              ; End of Dialog Callback MyDialogCallbackProc

;============================================================
;============================================================
;============================================================



string1 = 'a':@tab:'b':@tab:'c':@tab:'d':@tab:'e' 
string2 = 'm':@tab:'n':@tab:'o':@tab:'p':@tab:'q'

dlVariable1 = string1

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`Dual List Combo and editbox`
MyDialogX=002
MyDialogY=059
MyDialogWidth=294
MyDialogHeight=149
MyDialogNumControls=004
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`093,085,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,32,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`139,085,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`011,037,128,082,DROPLISTBOX,"DropListBox_1",dlVariable1,`:ItemExtract(1,string1,@tab):`,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`157,037,112,012,EDITBOX,"EditBox_1",ebVariable1,`:ItemExtract(1,string2,@tab):`,DEFAULT,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")





Title: Re: Filling an edit box from a drop list
Post by: seckner on October 02, 2013, 10:29:27 AM
David and Deana: thank you both! With your help it's now working - and I actually understand what we did! Thank you!