Descore
Providing Software Solutions to Canadian Resellers

Program Transitions: An Overview of Migrating from PRO/5 to BBj

Lets take a look at an older Character program(CUI) versus a newer BBj version(GUI). Well look at the code as well as the look and feel of each. In our first example we have a character based Salesperson masterfile input program.



The operator enters a new Salesperson code, an existing Salesperson code or the F4 key to exit the program.



If the Code entered is not on file then the operator is allowed to enter the Salesperson Name, MTD Sales, YTD Sales and LYR Sales figures.





If the code entered is not on file then the operator is given the choice of editing the Name field, Accepting the record as is or deleting the record from file.





Our next example shows a BBj graphical Salesperson masterfile screen.



The operator can key in a Salesperson code, or search for a code by using the search button , or by calling up a popup menu .

Either of these 2 ways will bring up a search dialogue for Salesperson lookup.



When a value is returned by the search program it fills in the Salesperson dialogue with the data from the Salesperson masterfile.



If the code entered is for an existing Salesperson then the operator has the ability to modify the Name field, clicking the button will write the information back to file, selecting the will display a dialogue asking



If the operator selects the , the program discards all data in the dialogue and clears out the fields. If the operator selects the button the control is returned back to the previous dialogue. Once back at the previous dialogue there is one additional selection, the button will end the program, destroying the window and return to the menu program.

If the operator enters a New Salesperson then the dialogue will allow entry of the Name, MTD Sales, YTD Sales, and Sales LYR.



Lets look at the difference in coding character versus graphical.

Character Program

0010 REM "SLSP+CO - Enter/Edit/Delete Sales Persons"
0020 BEGIN
0030 GOSUB TEMPLATES
0040 GOSUB OPEN_FILES
0050 GOSUB CONSTANTS
0100 REM ^100 "Screen"
0110 PRINT 'CS','SB','BOX'(0,0,80,3),'BOX'(0,10,80,3),@(1,1),DATE(0:"%Ds %Ms %
0110:D, %Y"),@(INT((80-LEN(HEADER$))/2),1),HEADER$,@(78,1),FID(0),
0120 PRINT @(20,4),"Code: ",@(17,5),"1. Name: ",@(12,6),"2. MTD Sales: ",@(12,
0120:7),"3. YTD Sales: ",@(12,8),"4. LYR Sales: ",'SF',
0200 REM ^100 "Code"
0210 PRINT 'CF','SF',; LET COL=26,ROW=4,PROMPT$="",TEXT$="",FILL$="-",LENGTH=2
0210:,CONTROL=0,FLAG$="u"; GOSUB STANDARDINPUT
0220 ON CONTROL-3 GOTO 0221,END_OF_PROGRAM
0230 LET SM.CODE$=PAD(TEXT$,CODELEN)
0235 PRINT @(COL,ROW),SM.CODE$,'CL',
0240 FIND RECORD(SM,KEY=SM.CODE$,DOM=0300)SM$
0250 PRINT @(26,5),SM.NAME$,'CL',@(26,6),SM.MTDSLS:OUTMASK$,'CL',@(26,7),SM.YT
0250:DSLS:OUTMASK$,'CL',@(26,8),SM.LYRSLS:OUTMASK$,'CL',
0260 PRINT @(12,6)," ",@(12,7)," ",@(12,8)," ",
0270 LET ONFILEFLAG$="Y"
0280 GOTO 0700
0300 REM ^100 "Name"
0310 PRINT @(26,5),'CL',; LET COL=26,ROW=5,PROMPT$="",TEXT$=SM.NAME$,FILL$="-"
0310:,LENGTH=25,CONTROL=0,FLAG$=""; GOSUB STANDARDINPUT
0320 ON CONTROL-2 GOTO 0321,0200,END_OF_PROGRAM
0330 LET SM.NAME$=TEXT$
0340 PRINT @(COL,ROW),SM.NAME$,'CL',
0400 REM ^100 "MTD Sales"
0405 IF ONFILEFLAG$>$$ THEN GOTO ACCEPT_ROUTINE FI
0410 PRINT @(26,6),'CL',; LET COL=26,ROW=6,PROMPT$="",TEXT$=STR(SM.MTDSLS),FIL
0410:L$="-",LENGTH=10,FLAG$="n"; GOSUB STANDARDINPUT
0420 ON CONTROL-2 GOTO 0421,0300,END_OF_PROGRAM
0430 LET SM.MTDSLS=NUM(TEXT$,ERR=0410)
0440 PRINT @(COL,ROW),SM.MTDSLS:OUTMASK$,'CL',
0500 REM ^100 "YTD Sales"
0505 IF ONFILEFLAG$>$$ THEN GOTO ACCEPT_ROUTINE FI
0510 PRINT @(26,7),'CL',; LET COL=26,ROW=7,PROMPT$="",TEXT$=STR(SM.YTDSLS),FIL
0510:L$="-",LENGTH=10,FLAG$="n"; GOSUB STANDARDINPUT
0520 ON CONTROL-2 GOTO 0521,0400,END_OF_PROGRAM
0530 LET SM.YTDSLS=NUM(TEXT$,ERR=0510)
0540 PRINT @(COL,ROW),SM.YTDSLS:OUTMASK$,'CL',
0600 REM ^100 "LYR Sales"
0605 IF ONFILEFLAG$>$$ THEN GOTO ACCEPT_ROUTINE FI
0610 PRINT @(26,8),'CL',; LET COL=26,ROW=8,PROMPT$="",TEXT$=STR(SM.LYRSLS),FIL
0610:L$="-",LENGTH=10,FLAG$="n"; GOSUB STANDARDINPUT
0620 ON CONTROL-2 GOTO 0621,0500,END_OF_PROGRAM
0630 LET SM.LYRSLS=NUM(TEXT$,ERR=0610)
0640 PRINT @(COL,ROW),SM.LYRSLS:OUTMASK$,'CL',
0700 REM ^100 "Accept/Delete Routine"
0710 ACCEPT_ROUTINE:
0720 PRINT @(1,11),FILL(78),; LET COL=12,ROW=11,PROMPT$="Press Line Number to
0720:Edit, Enter to Accept or 'F2' to Delete:",TEXT$="",LENGTH=1,CONTROL=0,FLA
0720:G$=""; GOSUB STANDARDINPUT
0730 ON CONTROL-1 GOTO 0731,DELETE_ROUTINE,0600,END_OF_PROGRAM
0740 LET LINENUM=NUM(TEXT$)
0750 ON LINENUM GOTO 0751,0300,0400,0500,0600
0760 LET SM$=FIELD(SM$)
0770 WRITE RECORD(SM,KEY=SM.CODE$)SM$
0780 LET ONFILEFLAG$=""
0790 PRINT 'SB',@(12,6),"2.",@(12,7),"3.",@(12,8),"4.",'SF',
0800 DIM SM$:FATTR(SM$)
0810 GOTO 0200
0900 REM ^100 "Delete a record"
0910 DELETE_ROUTINE:
0920 REMOVE (SM,KEY=SM.CODE$,DOM=0930)
0930 GOTO 0780
5000 REM 5000 "Standard Input"
5010 STANDARDINPUT:
5020 CALL "_stdinp.pub",ROW,COL,PROMPT$,TEXT$,FILL$,LENGTH,CONTROL,FLAG$
5030 RETURN
8000 REM 8000
8010 TEMPLATES:
8020 LET TEMP=UNT; OPEN (TEMP)"SM.tpl"
8030 READ (TEMP)TPL$
8040 CLOSE (TEMP)
8050 DIM SM$:TPL$
8060 RETURN
8100 OPEN_FILES:
8110 LET SM=UNT; OPEN (SM)PATH$+"SM--BA"
8120 RETURN
8200 CONSTANTS:
8210 LET HEADER$="Enter/Edit/Delete Sales People"
8230 LET CODELEN=2,OUTMASK$="###,##0.00-"
8240 RETURN
9000 REM 9000 "eoj"
9005 END_OF_PROGRAM:
9010 CLOSE (SM)
9020 RUN "MainMenu"



BBj Graphical Program

For a graphical program we can create and maintain our screen or dialogue in the Resbuilder program.



We define each of the controls we want on our dialogue by using the toolbar or images and placing them into the form. Each of the controls has its own unique control ID which a program uses to place or retrieve data to and from the dialogue.



The Salesperson code field is using an INPUTE control with event ID 100, it is placed at pixel X and Y location on the form of 125, 20 and is 40 pixels wide by 20 pixels high.

It is using a mask of AA to force only uppercase alpha characters to be entered in the field when this dialogue is presented by a program.

Once ALL control IDs have been defined on the form then a program can be written around the form.


rem "DescoreSalesperson.bbj - Enter/Edit/Delete Salespersons"
programWasCalled=(tcb(13)>0),TRUE=1,FALSE=0

switch programWasCalled
case FALSE
path$="//v/potest/files/",n$="BX",n1$="BA"
break
case DEFAULT
enter path$,n$
break
swend

call "DescorePaths.bbj",ResPath$,TemplatePath$,ImagePath$

gosub constants
gosub open_files

temp=unt;open(temp)TemplatePath$+"SM.tpl"
read(temp)tpl$
close(temp)
dim sm$:tpl$

our_context = sysGui!.getAvailableContext()
sysGui!.setContext(our_context)
rem "Open the Resource File"
res = sysGui!.resOpen(res$)
window! = sysGui!.createTopLevelWindow(res,res_id)
searchpopup! = sysGui!.createPopupMenu(res,101)
rem "Get the controls from the resource file"
code! = window!.getControl(CODE)
code!.setPopupMenu(searchpopup!)
slspSearch! = searchpopup!.getMenuItem(-1)
name! = window!.getControl(NAME)
mtdSls! = window!.getControl(MTDSLS)
ytdSls! = window!.getControl(YTDSLS)
lyrSls! = window!.getControl(LYRSLS)
acceptBtn! = window!.getControl(ACCEPTBTN)
deleteBtn! = window!.getControl(DELETEBTN)
exitBtn! = window!.getControl(EXITBTN)
exitBtn!.setCausesControlValidation(FALSE)
searchTbtn! = window!.getControl(SEARCHTBTN)

mtdSls!.setEnabled(TRUE)
ytdSls!.setEnabled(TRUE)
lyrSls!.setEnabled(TRUE)

call "Screen_Routine.bbj",gui
code!.focus()
callback(ON_CLOSE, exit_program, our_context)
callback(ON_LOST_FOCUS, getSlspCode, our_context, code!.getID())
callback(ON_TOOL_BUTTON_PUSH, SearchSlsp, our_context, searchTbtn!.getID())
callback(ON_POPUP_ITEM_SELECT, SearchSlsp, searchpopup!.getID(), slspSearch!.getID())
callback(ON_BUTTON_PUSH, acceptSlsp, our_context, acceptBtn!.getID())
callback(ON_BUTTON_PUSH, deleteSlsp, our_context, deleteBtn!.getID())
callback(ON_BUTTON_PUSH, exit_program, our_context, exitBtn!.getID())
process_events
getSlspCode:
code$ = code!.getText()
if code$ = "" then return fi
code$ = pad(code$,codelen)
find record(sm,key=code$,dom=NotOnFile)sm$
code!.setText(code$)
name!.setText(sm.NAME$)
mtdSls!.setText(str(sm.MTDSlS))
ytdSls!.setText(str(sm.YTDSLS))
lyrSls!.setText(str(sm.LYRSLS))
mtdSls!.setEnabled(FALSE)
ytdSls!.setEnabled(FALSE)
lyrSls!.setEnabled(FALSE)
return

NotOnFile:
name!.focus()
mtdSls!.setEnabled(TRUE)
ytdSls!.setEnabled(TRUE)
lyrSls!.setEnabled(TRUE)
return

SearchSlsp:
window!.setVisible(FALSE)
call "searchSlsp.bbj",sm,code$
window!.setVisible(TRUE)
if code$ > "" then
code!.setText(code$)
goto getSlspCode
fi
return

acceptSlsp:
sm.CODE$ = code!.getText()
sm.NAME$ = name!.getText()
sm.MTDSLS = num(mtdSls!.getText())
sm.YTDSLS = num(ytdSls!.getText())
sm.LYRSLS = num(lyrSls!.getText())
sm$ = field(sm$)
write record (sm,key=sm.CODE$)sm$
gosub clearFields
return

deleteSlsp:
answer = msgbox("Are You sure you want to Remove this record?" ,4,"Remove Record")
if answer<>6 then
return
fi
sm.CODE$ = code!.getText()
if sm.CODE$<>"" then
remove(sm,key=pad(sm.CODE$,codelen),dom=*next)
fi
gosub clearFields
return

clearFields:
code!.setText("")
name!.setText("")
mtdSls!.setText("")
ytdSls!.setText("")
lyrSls!.setText("")
code!.focus()
return

constants:
res$=ResPath$+"DescoreSalesPerson.brc",res_id=101
CODE=100,NAME=101,MTDSLS=102,YTDSLS=103,LYRSLS=104,ACCEPTBTN=105
DELETEBTN=106,EXITBTN=107
SEARCHTBTN=300,codelen=2
return

open_files:
sm = unt;open(sm)path$+"SM--"+n1$
environ = unt;open(environ)path$+"++++"+n$
gui = unt;open(gui)"X0"
BBj! = BBjAPI()
sysGui! = BBj!.getSysGui()
return

exit_program:
window!.destroy()
if programWasCalled then
close(sm)
close(environ)
close(gui)
exit
else
release
fi
return

COPYRIGHT © DESCORE INC., 2005
Bottom Logo