*********************************************************************
* RPG ILE MODULE CGIDEV2/RANDOMOUT
*
* After compiling this RPG MODULE,
* create the related program with the following command:
*
* CRTPGM CGIDEV2/RANDOMOUT MODULE(CGIDEV2/RANDOMOUT)
* ACTGRP(CGI) AUT(*USE)
*
*********************************************************************
/copy CGIDEV2/qrpglesrc,hspecs
/copy CGIDEV2/qrpglesrc,hspecsbnd
* Variables common to all CGIs
/copy CGIDEV2/qrpglesrc,prototypeb
/copy CGIDEV2/qrpglesrc,usec
/copy CGIDEV2/qrpglesrc,variables3
* Input variables parsed from the input string
D request s 10
D lng s 2
D mybet s 1
* Variables required by subprocedure "random"
DMyRandom s 10u 0 Random number
DMyLow s 10u 0 Low end of range
DMyHigh s 10u 0 High end of range
Dvarname s 50 for cgivarcnt and
Doscount s 10i 0 cgivarval
*
D servername s 256 variable names
*=====================================================================******
* PROLOG
* -Receive input from the remote browser
* -Parse it into program variables
*=====================================================================******
/copy CGIDEV2/qrpglesrc,prolog3
C eval request = zhbgetvarupper('request')
C eval lng = zhbgetvarupper('lng')
C eval mybet = zhbgetvarupper('mybet')
*=====================================================================******
* MAIN LINE
*=====================================================================******
* Load externally defined output html
C eval lng = uppify(lng)
C callp gethtml('DEMOHTML' + %trimr(lng):
C 'CGIDEV2':
C 'RANDOMOUT':
C '«as400»')
* Select main action
C select
C when request = ' '
C exsr Case1
C when request «» ' '
C exsr Case2
C endsl
* Back to caller
C exsr Exit
*====================================================================
* Start the bet
*====================================================================
C Case1 begsr
* Set HTML output variables
C exsr setvardata
* Write HTML section
C callp wrtsection('input')
*
C endsr
*====================================================================
* Perform the bet
*====================================================================
C Case2 begsr
* Generate a random number
C exsr CallRandom
* Get random number into "outnumber1"
C move MyRandom outnumber 10
C move outnumber outnumber1 1
* Set HTML output variables
C exsr setvardata
* Write sections of HTML. Wrtsection handles variable substitution using the
* variables that have been prepared by the setvardata subroutine.
*
C callp wrtsection('output')
*
C if mybet = Outnumber1
C callp wrtsection('win')
C else
C callp wrtsection('lose')
C endif
*
C callp wrtsection('again')
*
C if mybet = Outnumber1
C callp wrtsection('pinball')
C endif
*
C callp wrtsection('end')
*
C endsr
*=====================================================================******
* Call random subprocedure
* Returns a random unsigned integer between low and high
* Valid ranges are 1 to 327,702,767
*
* This subroutine asks for a random integer
* between 0 and 9, to be returned in variable "MyRandom"
*=====================================================================******
C CallRandom begsr
C eval MyLow = 1
C eval MyHigh = 9
C eval MyRandom = random(MyLow:MyHigh)
C endsr
*=====================================================================******
* Setvardata - Sets values of variable names, contents, lengths
*
* This subroutine, if desired, can be written as multiple subroutines:
* for example, one subroutine for each section that contains any
* variables.
*=====================================================================******
C setvardata begsr
* Retrieve server name
C eval serverName=getenv('SERVER_NAME':qusec)
C callp updHTMLvar('servername':servername:
C InitHTMLVars)
C callp updHTMLvar('INNUMBER':mybet)
C callp updHTMLvar('OUTNUMBER':outnumber1)
C endsr
*=====================================================================******
* Program status subroutine
*=====================================================================******
C *pssr begsr
* If have already been in pssr, get out to avoid looping
C if pssrswitch=*on
C eval *inlr = *on
C return
C endif
* Set on switch to indicate we've been here
C eval pssrswitch=*on
* Write HTML sections (top if not already done, pssr, and *fini)
C if wrotetop=*off
C callp wrtsection('top')
C endif
C callp wrtsection('pssr')
*
C exsr Exit
C endsr
*=====================================================================
* Back to caller
*=====================================================================
C Exit begsr
* Do not delete the call to wrtsection with section name *fini. It is needed
* to ensure that all output html that has been buffered gets output.
C callp wrtsection('*fini')
C return
C endsr
|