4gl

DATABASE ds
 
GLOBALS "../../config/top.global"
 
DEFINE g_curs_index           LIKE type_file.num10
DEFINE g_row_count           LIKE type_file.num10
DEFINE g_imas                    INTEGER
DEFINE g_ima                      INTEGER
DEFINE g_sure                     STRING
DEFINE g_ima121                INTEGER
DEFINE g_ima122                INTEGER
DEFINE g_ima123                INTEGER
 
MAIN
   OPTIONS
        INPUT NO WRAP
   DEFER INTERRUPT
   IF (NOT cl_user()) THEN
      EXIT PROGRAM
   END IF
   WHENEVER ERROR CALL cl_err_msg_log
   IF (NOT cl_setup("AZZ")) THEN
      EXIT PROGRAM
   END IF
   CALL cl_used(g_prog,g_time,1) RETURNING g_time
   OPEN WINDOW p_zz_w WITH FORM "azz/42f/p_test" ATTRIBUTE(STYLE=g_win_style CLIPPED)
   CALL cl_ui_init()
   LET g_action_choice = ""
   DISPLAY base.Application.getProgramName() TO name
   INITIALIZE g_imas TO NULL
   LET g_sure="N"
   CALL test_menu()
   CLOSE WINDOW p_zz_w
      CALL  cl_used(g_prog,g_time,2) RETURNING g_time #No:MOD-580088  HCN 20050818  #No.FUN-6A0096
END MAIN
 
FUNCTION test_count()
  WHILE TRUE
     INITIALIZE g_ima121 TO NULL
     INITIALIZE g_ima122 TO NULL
     INITIALIZE g_ima123 TO NULL
     CLEAR FORM
     MESSAGE ''
     DISPLAY g_sure TO s123
     INPUT  g_ima121,g_ima122 FROM ima121,ima122
         LET g_ima123=g_ima121+g_ima122
         LET g_ima=g_ima123
     IF INT_FLAG THEN
               MESSAGE "crash!!"
               LET INT_FLAG = 0
               EXIT WHILE
     END IF
     LET g_imas=g_ima
     DISPLAY g_ima121 TO ima121
     DISPLAY g_ima122 TO ima122
     DISPLAY g_ima123 TO ima123
     IF g_ima123 IS NULL THEN
            CONTINUE WHILE
     ELSE
            MESSAGE "count successfully!!" ATTRIBUTE (YELLOW)
     END IF
   EXIT WHILE
  END WHILE
END FUNCTION
 
FUNCTION test_menu()
  MENU ""
        BEFORE MENU
           CALL cl_navigator_setting(g_curs_index, g_row_count)
        ON ACTION insert
            LET g_action_choice="insert"
                 CALL test_count()
        ON ACTION query
            LET g_action_choice="query"
        ON ACTION sure
           CALL test_sure()
        ON ACTION modify
            LET g_action_choice="modify"
            IF g_sure MATCHES "[Y]" THEN
                MESSAGE "can't not change"
            ELSE
                 CALL test_sq()
            END IF
        ON ACTION invalid
            LET g_action_choice="invalid"
        ON ACTION exit
            LET g_action_choice = "exit"
            EXIT MENU
        ON ACTION controlg
            CALL cl_cmdask()
        ON ACTION locale
            CALL cl_dynamic_locale()
          CALL cl_show_fld_cont()                   #No:FUN-550037 hmf
        ON IDLE g_idle_seconds
           CALL cl_on_idle()
           CONTINUE MENU
      ON ACTION about         #MOD-4C0121
         CALL cl_about()      #MOD-4C0121
        COMMAND KEY(INTERRUPT)
             LET INT_FLAG=FALSE         #MOD-570244    mars
           LET g_action_choice = "exit"
           EXIT MENU
         ON ACTION related_document    #No:MOD-470515
           LET g_action_choice="related_document"            
    END MENU
END FUNCTION
 
FUNCTION test_sq()
     MESSAGE ''
     LET g_imas=0
     IF g_ima MATCHES "[0]" OR g_ima IS NULL THEN
          MESSAGE "!g_ima123=0"
     ELSE
           LET g_ima121=g_ima
           LET g_ima122=g_ima
           LET g_imas=g_ima121*g_ima122
           DISPLAY g_ima121 TO ima121
           DISPLAY g_ima122 TO ima122
        DISPLAY g_imas TO ima123
        LET g_ima=g_imas
     END IF
END FUNCTION
 
FUNCTION test_sure()
  IF g_sure="N" THEN
    IF g_imas IS NULL OR g_imas MATCHES "[0]" THEN
        MESSAGE "g_imas is null !!"
    ELSE
        LET g_sure="Y"
      DISPLAY g_sure TO s123
      MESSAGE ''
    END IF
  ELSE
      MESSAGE "Have been identified!"
  END IF
END FUNCTION

4fd

<?xml version="1.0" encoding="UTF-8" ?>
<Form CHECKSUM="-1" browserStatus="true" database_name="ds" fourSTFile="" gstVersion="11401" height="25" lstrtext="false" lstrtoallcomment="false" lstrtoallitem="false" lstrtoalltext="false" lstrtoalltitle="false" name="p_test" posX="0" posY="0" spacing="normal" text="p_test" width="91">
<Grid fontPitch="default" height="16" hidden="--------" hrecindex="-1" lstrcomment="false" name="gr16" posX="1" posY="1" width="74">
<Text height="1" hrecindex="-1" name="text38" posX="16" posY="1" text="這是手寫的第一個簡單的不能再簡單的,簡單的甚至都不叫做4gl的4gl" width="34"/>
<Text height="1" name="text40" posX="25" posY="3" text="下面將實現一個簡單的計算器功能" width="15"/>
<FormField colName="ima121" fieldtype="FORM_ONLY" name="ima121" sqlDBName="formonly" sqlTabName="formonly">
<Edit autoNext="--------" case="NONE" century="R" color="black" colorCondition="black" data_type="INTEGER" fontPitch="default" formfieldname="formfield0" height="1" hidden="--------" invisible="--------" justify="none" lstrcomment="false" name="ima121" noEntry="--------" notNull="--------" posX="26" posY="5" required="--------" reverse="--------" scroll="--------" sizePolicy="initial" tabIndex="1" verify="--------" width="8"/>
</FormField>
<FormField colName="ima122" fieldtype="FORM_ONLY" name="ima122" sqlDBName="formonly" sqlTabName="formonly">
<Edit autoNext="--------" case="NONE" century="R" color="black" colorCondition="black" data_type="INTEGER" fontPitch="default" formfieldname="formfield1" height="1" hidden="--------" invisible="--------" justify="none" lstrcomment="false" name="ima122" noEntry="--------" notNull="--------" posX="26" posY="7" required="--------" reverse="--------" scroll="--------" sizePolicy="initial" tabIndex="2" verify="--------" width="8"/>
</FormField>
<Text height="1" name="text26" posX="9" posY="5" text="num1" width="4"/>
<Text height="1" name="text27" posX="9" posY="7" text="num2" width="4"/>
<FormField colName="name" fieldtype="FORM_ONLY" name="name" sqlTabName="formonly">
<Edit autoNext="--------" case="NONE" century="R" color="black" colorCondition="black" data_type="VARCHAR" fontPitch="default" formfieldname="formfield0" height="1" hidden="--------" invisible="--------" justify="none" lstrcomment="false" name="name" noEntry="--------" notNull="--------" posX="5" posY="3" required="--------" reverse="--------" scroll="--------" sizePolicy="initial" tabIndex="5" verify="--------" width="17"/>
</FormField>
<Label color="black" colorCondition="black" flag_text_changed="TRUE" fontPitch="default" height="1" hidden="--------" justify="none" lstrcomment="false" lstrtext="false" name="lb15_1" posX="9" posY="11" sizePolicy="initial" text="確認碼" width="6"/>
<FormField colName="s123" fieldtype="FORM_ONLY" name="s123" sqlDBName="formonly" sqlTabName="formonly">
<Edit autoNext="--------" case="NONE" century="R" color="black" colorCondition="black" data_type="INTEGER" fontPitch="default" formfieldname="formfield2" height="1" hidden="--------" invisible="--------" justify="none" lstrcomment="false" name="s123" noEntry="--------" notNull="--------" posX="26" posY="11" required="--------" reverse="--------" scroll="--------" sizePolicy="initial" tabIndex="4" verify="--------" width="8"/>
</FormField>
<FormField colName="ima123" fieldtype="FORM_ONLY" hrecindex="-1" name="ima123" sqlDBName="formonly" sqlTabName="formonly">
<Edit autoNext="--------" case="NONE" century="R" color="black" colorCondition="black" data_type="INTEGER" fontPitch="default" formfieldname="formfield0" height="1" hidden="--------" invisible="--------" justify="none" lstrcomment="false" name="ima123" noEntry="--------" notNull="--------" posX="26" posY="9" required="--------" reverse="--------" scroll="--------" sizePolicy="initial" tabIndex="3" verify="--------" width="18"/>
</FormField>
<Text height="1" name="text5" posX="9" posY="9" text="num3" width="4"/>
</Grid>
</Form>

文章来源: 放牛娃blog | 个人技术小站