;LOTTERY.WAS v1.00 ASPECT script to generate lottery numbers

;****************************************************************************
;* Written by:  Symantec ASPECT Assist                                       *
;*                                                                           *                                                                             
;* This script file will give the user the option of either capturing data   *
;* in half hour increments, or in 24 hour increments. The Capture file will  *
;* close after a predefined period of inactivity on the port.                *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************




;****************************************************************************
;* GLOBAL VARIABLES                                                         *
;****************************************************************************

string gszLuckyNum                     ;user entered lucky number

integer giNumbers[6]                   ;array that contains all numbers
integer giLuckyNum                     ;integer value of the lucky number
integer giGenerate=1                   ;flag



;****************************************************************************
;*                                                                          *   
;* MAIN                                                                     * 
;*                                                                          *  
;* The Main procedure calls the procedures that provide the necessary user  *
;* interface dialog boxes and number generating routines.                   *
;*                                                                          *
;* Calls:  GatherInformation, Waiting, Generate, Duplicates, DisplayNumbers *
;* Modifies globals: None                                                   *
;*                                                                          *
;****************************************************************************

proc Main
   GatherInformation()                 ;get lucky number procedure
   Waiting()                           ;display generating dialog box
   Generate()                          ;generate all of the numbers
   Duplicates()                        ;make sure there are no duplicates
   DisplayNumbers()                    ;display the results
endproc



;****************************************************************************
;*                                                                          *   
;* GATHERINFORMATION                                                        * 
;*                                                                          *  
;* The procedure GatherInformation prompts the user for their lucky number. *
;* interface dialog boxes and number generating routines.                   *
;*                                                                          *
;* Calls:  CheckFormat                                                      *
;* Called by: Main                                                          *
;* Modifies globals: gszLuckyNum                                            *
;*                                                                          *
;****************************************************************************

proc GatherInformation
   while giGenerate==1                 ;loop while while giGenerate = 1
      if sdlginput "Power Ball Numbers Generator" "Please enter your two \
digit lucky number: " gszLuckyNum 2    ;prompt and retrieve the lucky number
         CheckFormat()                 ;make sure the entry is valid
      else                             ;if they want to cancel
         halt                          ;exit the script
      endif
   endwhile
endproc



;****************************************************************************
;*                                                                          *   
;* CHECKFORMAT                                                              * 
;*                                                                          *  
;* The procedure CheckFormat insures that the value entered for the lucky   *
;* number is in the correct format.                                         *
;*                                                                          *
;* Calls:  None                                                             *
;* Called by: GatherInformation                                             *
;* Modifies globals: giGenerate, giLuckyNum                                 *
;*                                                                          *
;****************************************************************************

proc CheckFormat
integer iYesNo                         ;results of YESNO question

   if nullstr gszLuckyNum              ;check to see if the entry is blank
      errormsg "Please enter a lucky number!"
      return
   endif

   atoi gszLuckyNum giLuckyNum         ;convert the entry to an integer

   if giLuckyNum==0                    ;if the result is 0, the entry is 
                                       ;not valid
      errormsg "Zeros and letters are not valid for lucky numbers.  Please \
enter your lucky number."
      return
   endif
                                       ;confirm the users input
   strfmt s0 "You entered %s as your lucky number.  Is this correct?" gszLuckyNum
   sdlgmsgbox "Power Ball Lottery Number Generator" s0 QUESTION YESNO iYesNo

   if iYesNo==7  
      return                           ;return and get the number again
   endif
   giGenerate=0                         ;the information is valid and correct
endproc



;****************************************************************************
;*                                                                          *   
;* GENERATE                                                                 * 
;*                                                                          *  
;* The procedure Generate runs a loop which passes the pointer value to the *
;* GetRand procedure.  This is done so that individual numbers can be       *
;* generated if a duplicate is found.                                       *
;*                                                                          *
;* Calls:  GetRand(integer)                                                 *
;* Called by: Main                                                          *
;* Modifies globals: None                                                   *
;*                                                                          *
;****************************************************************************

proc Generate
integer iPtr

   for iPtr = 0 upto 5                 ;loop from 0 up to 5
      GetRand(&iPtr)                   ;generate the number, passing the pointer
      pause 2                          ;allow time for the clock to change
   endfor
endproc



;****************************************************************************
;*                                                                          *   
;* GETRAND                                                                  * 
;*                                                                          *  
;* The procedure GetRand does the actual calculations of the lottery        *
;* numbers.  It has been made stand alone so that a single number can be    *
;* generated if a duplicate is found.                                       *
;*                                                                          *
;* Calls:  None                                                             *
;* Called by:  Generate                                                     *
;* Modifies globals:  giNumbers[]                                           *
;*                                                                          *
;****************************************************************************

proc GetRand
param integer iPtr                     ;value of the passed in pointer

float fTemp                            ;temporary value
float fSeed                            ;used to generate the seed value

integer iNum                           ;temporary value
integer iModNum=46                     ;sets limit for maximum number value

   if iPtr==0                          ;if the pointer is 0, use the 
      fSeed =$LTIME * giLuckyNum       ;lucky number to assist in generation
   else
      fSeed=$LTIME                     ;fSeed equals the long system time
   endif
   fSeed = (fSeed * 15625.0 + 22221.0) % 65536.0
   fTemp = fSeed / 65535.0             ;make the value a decimal number
   fTemp = (fTemp<0)?-fTemp:fTemp      ;get the absolute value of the number
   iNum = fTemp * 45 + 1               ;make a whole number and not a decimal
   rand giNumbers[iPtr] iNum           ;generate a random number
   giNumbers[iPtr] = giNumbers[iPtr] % iModNum
                                       ;Make sure it is less than 46
endproc



;****************************************************************************
;*                                                                          *   
;* DISPLAYNUMBERS                                                           * 
;*                                                                          *  
;* The procedure DisplayNumbers converts all of the numbers into string     *
;* values and then displays them in a dialog box.                           *
;*                                                                          *
;* Calls:  None                                                             *
;* Called by: Main                                                          *
;* Modifies globals: None                                                   *
;*                                                                          *
;****************************************************************************

proc DisplayNumbers
integer iEvent                         
integer iPointer

string szWhiteDot1                     ;path to white ball graphic
string szWhiteDot2                     ;path to white ball graphic
string szWhiteDot3                     ;path to white ball graphic
string szWhiteDot4                     ;path to white ball graphic
string szWhiteDot5                     ;path to white ball graphic
string szRedDot                        ;path to red ball graphic
string szRed
string szWhite1                        ;used to construct the file name
string szWhite2
string szWhite3
string szWhite4
string szWhite5


   szWhiteDot1 = $ASPECTPATH            ;get path to the ASPECT directory
   szWhiteDot2 = $ASPECTPATH
   szWhiteDot3 = $ASPECTPATH
   szWhiteDot4 = $ASPECTPATH
   szWhiteDot5 = $ASPECTPATH
   szRedDot = $ASPECTPATH

   for iPointer = 1 upto 45            ;loop from 1 to 45
      if iPointer==giNumbers[0]        ;if the loop value and the number match
         strfmt szRed "RED%d.BMP" iPointer
      endif                            ;construct the name for the appropriate
      if iPointer==giNumbers[1]        ;graphic file
         strfmt szWhite1 "WHITE%d.BMP" iPointer
      endif
      if iPointer==giNumbers[2]
         strfmt szWhite2 "WHITE%d.BMP" iPointer
      endif
      if iPointer==giNumbers[3]
         strfmt szWhite3 "WHITE%d.BMP" iPointer
      endif
      if iPointer==giNumbers[4]
         strfmt szWhite4 "WHITE%d.BMP" iPointer
      endif
      if iPointer==giNumbers[5]
         strfmt szWhite5 "WHITE%d.BMP" iPointer
      endif
   endfor
                                       
   addfilename szWhiteDot1 szWhite1    ;add the filename to the path
   addfilename szWhiteDot2 szWhite2
   addfilename szWhiteDot3 szWhite3
   addfilename szWhiteDot4 szWhite4
   addfilename szWhiteDot5 szWhite5
   addfilename szRedDot szRed

   statclear                           ;clear the status line of messages

   dialogbox 0 62 59 210 115 27 "Power Ball Numbers Generator"
      text 13 5 19 55 8 "Lottery numbers:" left
      text 14 5 60 64 8 "Power Ball number:" left
      pushbutton 15 85 89 40 14 "&OK" default
      bitmap 1 70 11 30 30 szWhiteDot1
      bitmap 2 95 11 30 30 szWhiteDot2
      bitmap 3 120 11 30 30 szWhiteDot3
      bitmap 4 145 11 30 30 szWhiteDot4
      bitmap 5 170 11 30 30 szWhiteDot5
      bitmap 6 120 51 30 30 szRedDot
   enddialog

   while iEvent !=15                    ;loop while the user is viewing the results
      dlgevent 0 iEvent                 ;get the value of the current event
      yield
   endwhile
endproc



;****************************************************************************
;*                                                                          *   
;* WAITING                                                                  * 
;*                                                                          *  
;* The procedure Waiting displays a dialog box informing the user that the  *
;* numbers are being generated.                                             *
;*                                                                          *
;* Calls:  None                                                             *
;* Called by:  Main                                                         *
;* Modifies globals:  None                                                  *
;*                                                                          *
;****************************************************************************

proc Waiting
   statmsg "Generating numbers..."
   dialogbox 0 96 100 167 65 7 "Power Ball Numbers Generator"
      text 1 27 17 115 27 "Please wait while the numbers are generated... \
This may take up to 30 seconds." left
   enddialog
endproc



;****************************************************************************
;*                                                                          *   
;* DUPLICATES                                                               * 
;*                                                                          *  
;* The procedure Duplicates loops to check and see if there were any        *
;* duplicate numbers generated.                                             *
;*                                                                          *
;* Calls:  ChangeEm                                                         *
;* Called by:  Main                                                         *
;* Modifies globals:  None                                                  *
;*                                                                          *
;****************************************************************************

proc Duplicates
integer iChange=1
integer iValue=0

   while iChange!=iValue               ;loop while there are duplicate numbers
      iValue=ChangeEm()                 
   endwhile
endproc



;****************************************************************************
;*                                                                          *   
;* CHANGEEM(integer Change)                                                 * 
;*                                                                          *  
;* The function ChangeEm does the acutal checking for duplicate numbers by  *
;* using two for loops.  If a duplicate entry is found, the value of the    *
;* pointer is passed to the GetRand procedure so that only the duplicate    *
;* number will be regenerated.                                              *
;*                                                                          *
;* Calls:  GetRand(integer)                                                 *
;* Called by:  Duplicate                                                    *
;* Modifies globals:  None                                                  *
;*                                                                          *
;****************************************************************************

func ChangeEm: Integer
integer iPtr1                          ;pointer number 1
integer iPtr2                          ;pointer number 2
integer iChange=0                      ;value to be returned by the function

      statmsg "Checking for duplicate numbers..."
      for iPtr1 = 1 upto 4             ;0 is powerball so no need to compare
         for iPtr2= 2 upto 5
            if iPtr1!=iPtr2            ;no need to compare if the pointers equal
               if giNumbers[iPtr1] == giNumbers[iPtr2]
                                       ;if the values of the pointers are equal,
                                       ;then there is a duplicate number
                  pause 1              ;allow time for the $LTIME value to chane
                  GetRand(&iPtr2)      ;Change the second occurance
                  return iChange       ;return a 0 so it will loop again
               else
                  iChange=1            ;no duplicates were found so no need to loop
               endif
            endif
         endfor
      endfor
   return iChange
endfunc
