#define mv_pan1,mv_pan2 CHAR(19) #Define mv_data1,mv_data2 char(11) #define mv_name char(26) DEFINE mv_card RECORD pan CHAR(19), name CHAR(26), expire CHAR(4), service CHAR(3), data1 CHAR(60), data2 CHAR(60) END RECORD DEFINE mv_cardscanned CHAR(256) DEFINE mv_firsttime INTEGER FUNCTION get_lastcard_pan() return mv_card.pan END FUNCTION FUNCTION get_lastcard_name() return mv_card.name END FUNCTION FUNCTION get_lastcard_surname() define lv_indexof integer define a_name char(256) let a_name=mv_card.name if a_name matches "*/*" then let lv_indexof=aclfgl_indexof(a_name,"/") if lv_indexof>0 then let a_name=a_name[1,lv_indexof-1] end if end if return a_name END FUNCTION FUNCTION get_lastcard_details() return mv_card.pan, mv_card.name,mv_card.expire END FUNCTION # enable/disable card scanning # call initialize_card_reader(false) # from within main to disable card scanning # and then use # scan_card() # to enable it - and return the value you want... FUNCTION initialize_card_reader (lv_set) # Parameters DEFINE lv_set INTEGER # Normal Variables DEFINE lv_keycode INTEGER if mv_firsttime = false then # Reverse logic to catch the default value of NULL else call form_is_compiled(a4gl_fcard,"MEMPACKED","GENERIC") call form_is_compiled(a4gl_fcard2,"MEMPACKED","GENERIC") let mv_firsttime=false end if # Assuming F36 isn;t used for anything else... LET lv_keycode=fgl_keyval("F36") # define %B to be recognised by ncurses at "F36" CALL ui.curses.define_key("%B",300) IF lv_set THEN # Set up a callback to the 4gl function 'get_scanned_code' whenever F36 is pressed code aclfgl_key_callback(aclfgl_get_scanned_code,lv_keycode); endcode ELSE # Add the inital callback for F36 so it will discard the data... code aclfgl_key_callback(aclfgl_dump_scanned_code,lv_keycode); endcode END IF END FUNCTION # open the window to allow a card scan to take place and then read the card # and return the primary information... FUNCTION scan_card () DEFINE lv_data CHAR(80) DEFINE lv_exp_month INTEGER DEFINE lv_exp_yr INTEGER initialize mv_card.* TO NULL initialize mv_cardscanned TO NULL CALL initialize_card_reader(TRUE) let lv_data= " " OPEN WINDOW w_card AT 10,10 WITH FORM "a4gl_fcard" ATTRIBUTES(BORDER, MESSAGE LINE LAST, form line 1,error line last,style="ds.") let int_flag=false INPUT lv_data WITHOUT DEFAULTS FROM carddata ON KEY (F36) CALL get_card_details() RETURNING mv_card.* if mv_card.pan is NULL THEN exit input end if IF mv_card.expire IS NULL THEN message "No card expiry date" CONTINUE INPUT END IF LET lv_exp_yr=mv_card.expire[1,2] # Anything after 1980... IF lv_exp_yr<80 THEN LET lv_exp_yr=lv_exp_yr+2000 ELSE LET lv_exp_yr=lv_exp_yr+1900 END IF LET lv_exp_month=mv_card.expire[3,4] IF YEAR(TODAY)>lv_exp_yr THEN message "Card has expired" CONTINUE INPUT ELSE # It runs out this year - so what about the month IF YEAR(TODAY)=lv_exp_yr AND lv_exp_month