Search code examples
openedgeprogress-4gl

How to get chosen value from combo-box as variable PROGRESS 4GL


while doing a task I run into problem, I do not know how to obtain value from combo-box as variable, I have read a lot of documentation, but did not found a solution, maby you can advise me.

DEFINE VARIABLE StateBox AS CHARACTER FORMAT "X(256)":U 
         LABEL "Pick a Satete" 
         VIEW-AS COMBO-BOX INNER-LINES 5 
         DROP-DOWN-LIST
         SIZE 16 BY 1 NO-UNDO.
     
    DEFINE FRAME StateCombo
            StateBox
        WITH CENTERED ROW 4.
 
     FOR EACH State NO-LOCK BREAK BY State.StateName:
        StateBox:ADD-LAST(State.StateName) IN FRAME StateCombo. 
    END.
    
    vStateText = (SCREEN-VALUE:StateBox). //ERROR
    
    ENABLE StateBox WITH FRAME StateCombo.
    APPLY "VALUE-CHANGED" TO StateBox IN FRAME StateCombo.
    WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. //COMBO-BOX CREATED

I tried SCREEN-VALUE, STREAM, I want to get a solution


Solution

  • You should

    WAIT-FOR GO OF CURRENT-WINDOW.
    

    and as Peter said, it must be StateBox:SCREEN-VALUE, there is no need for APPLY VALUE-CHANGED, so this will work:

    ENABLE StateBox WITH FRAME StateCombo.
    WAIT-FOR GO OF CURRENT-WINDOW. //COMBO-BOX CREATED
    
    DEFINE VARIABLE vStateText AS CHARACTER NO-UNDO .
    vStateText = (StateBox:SCREEN-VALUE). //ERROR
    
    MESSAGE vStateText
        VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
    

    But as StateBox is also a CHARACTER-Variable, you don't need the extra variable vStateText:

    ENABLE StateBox WITH FRAME StateCombo.
    WAIT-FOR GO OF CURRENT-WINDOW. //COMBO-BOX CREATED
    
    ASSIGN StateBox .
    MESSAGE StateBox
        VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.
    

    The ASSIGN statement without the = operator will assign the screen-value to the same named variable.