|
Post by Walt Decker on Aug 28, 2022 19:13:52 GMT -5
After encapsulating the procedures I was able to duplicate the double click problem with my mouse. I change graphic buttons to radio buttons, deleted the dummy button and set focus to the graphic logo, and added a clock to the code. For some reason, setting the window default font over-rides all the other font declarations so I commented that out. I added several routines to aid in app setup. The encapsulated app follows:
' nomainwin [DEFINE.GLOBALS] DIM Totals(12, 7) 'month, shift DIM Month$(12) 'load array with month names
GLOBAL CR$, _ 'ascii carriage RETURN NULL$ 'ascii null
GLOBAL Hour1, _ 'first shift Hour6, _ 'last shift ItsNewYear, _ 'prob not a new year RptWinOpen, _ 'is the rpt window open? NewYear, _ ProcYY, _ ProcDD, _ TodayDD, _ FileOpen, _ DataIn ' ' set up some variables for path and file names ' GLOBAL FilePath$, _ FileName$, _ DevPath$, _ BackupName$, _ LogoSpec$, _ Greenspec$, _ RedSpec$, _ Today$
[DEFINE.GLOBALS.END]
[INITIALIZE.GLOBALS] CR$ = CHR$(13) 'ascii carriage RETURN NULL$ = CHR$(0) 'ascii null
Hour1 = 9 'first shift Hour6 = 14 'last shift ItsNewYear = 0 'prob not a new year RptWinOpen = 0 'is the rpt window open? NewYear = 0 ProcYY = 0 ProcDD = 0 FileOpen = 0 DataIn = 0
FilePath$ = DefaultDir$ + "\" FileName$ = FilePath$ + "DriveUp.dat" DevPath$ = FilePath$ + "Dev\" BackupName$ = FilePath$ + "DriveUpBackUp.dat" LogoSpec$ = DevPath$ + "PVLogo.bmp" Greenspec$ = DevPath$ + "greenBut.bmp" RedSpec$ = DevPath$ + "redBut.bmp" Today$ = Date$("mm/dd/yy") TodayDD = VAL(MID$(Today$, 4, 2)) 'day number
[GLOBAL.INIT.END]
CALL SET.MONTH
RetVal = FN.IsFolder(DevPath$) FileOpen = FN.OpenFile(FileName$) IF FileOpen > 0 THEN DataIn = FN.GetData() TRACE 2 IF DataIn THEN NewYear = VAL(RIGHT$(Today$, 2)) IF NewYear <> ProcYY THEN 'GOSUB [NewYear] TRACE 2 RetVal = FN.NewYear() CALL REPORT.BUTTON "#main.totBut" END IF ' RetVal = FN.ShowTotals() ELSE FileOpen = FN.OpenFile(FileName$) RetVal = FN.WriteData() CALL BACKUP.DATA END IF END IF
RetVal = FN.CreateCountWin() PRINT #main.logo, "SETFOCUS"
IF ProcDD = TodayDD THEN 'not the first time today RetVal = FN.ShowTotals() ELSE FileOpen = FN.OpenFile(FileName$) RetVal = FN.WriteData() CALL BACKUP.DATA END IF
TIMER 21600000, END.LOG
CALL SET.TIME WAIT
'-------------------------------------- '--------------------------------------
SUB SET.MONTH
MonthNames$ = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
FOR I = 1 TO 12 Month$(I) = WORD$(MonthNames$, I) NEXT I END SUB
'-------------------------------------- '--------------------------------------
SUB SET.TIME
[SET.CLOCK] PRINT #main.Time, TIME$() SCAN CALLDLL #kernel32, "Sleep", 100 AS LONG, RetVal AS VOID GOTO [SET.CLOCK] END SUB
'-------------------------------------- '--------------------------------------
SUB MSG Title$, Message$
CRLF$ = CHR$(13) + CHR$(10)
NOTICE Title$ + CRLF$ + Message$
END SUB
'-------------------------------------- '--------------------------------------
SUB END.LOG WinHndl$
CLOSE #WinHndl$ END END SUB
'-------------------------------------- '--------------------------------------
SUB BUTTON.CLICK RdoHndl$
BtnState$ = ""
BtnSet = 0
PRINT #RdoHndl$, "VALUE? BtnState$"
BtnState$ = UPPER$(BtnState$)
SELECT CASE RdoHndl$ CASE "#main.greenBut" IF BtnState$ = "SET" THEN BtnSet = 1 CASE "#main.redBut" IF BtnState$ = "SET" THEN BtnSet = -1 END SELECT
PRINT #main.logo, "SETFOCUS" RetVal = FN.CalcClicks(BtnSet) END SUB
'-------------------------------------- '--------------------------------------
SUB REPORT.BUTTON ReptHndl$
IF Totals(0, 0) = 0 THEN CALL MSG "NO DATA", "No data found for " + Date$() EXIT SUB END IF
RetVal = FN.GenerateReport() END SUB
'-------------------------------------- '--------------------------------------
SUB BACKUP.DATA
OPEN BackupName$ FOR RANDOM AS #BackFile LEN = 8 FIELD #BackFile, 8 AS Buff
Buff = Totals(0, 0) 'don't forget the date PUT #BackFile, 1
FOR I = 0 TO 12 FOR J = 1 TO 7 RecNo = I * 7 + J + 1 Buff = Totals(I, J) PUT #BackFile, RecNo NEXT J NEXT I
CLOSE #BackFile END SUB
'-------------------------------------- '-------------------------------------- FUNCTION FN.CalcClicks(Adjust)
Month = VAL(LEFT$(Today$, 2)) 'get the month number (row) Hour = VAL(LEFT$(TIME$(), 2)) 'get the hour (col)
IF (Hour < Hour1) OR (Hour > Hour6) THEN Hour = 15 'put it in "Other" (i.e. shift 7) END IF
Shift = Hour - 8 'xlate hour # to shift # ' ' Update the monthly total ' OpenFile = FN.OpenFile(FileName$) 'GOSUB [OpenFile]
OldVal = Totals(Month, Shift) 'get the old value NewVal = OldVal + Adj 'increment/decrement it
IF NewVal < 0 THEN NewVal = 0 'no negative values
Totals(Month, Shift) = NewVal 'update the array
FIELD #DataFile, 8 AS Buff
Buff = NewVal RecNo = Month * 7 + Shift + 1 'get the record number PUT #DataFile, RecNo 'update the file ' ' Update today's total (***seems like the problem is here***) ' OldVal = Totals(0, Shift) 'get the old value for today 'notice "OV= " + CR$ + str$(OldVal) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NewVal = OldVal + Adjust 'inc/dec by 1 'notice "NV= " + CR$ + str$(NewVal) '~~~~~~~~~~~~~~~~~~~~~~~~~~~
IF NewVal < 0 THEN NewVal = 0 'no negative values
Totals(0, Shift) = NewVal 'update the array Buff = NewVal RecNo = Shift + 1 'get the record number PUT #DataFile, RecNo 'update the current section of the file CLOSE #DataFile 'keep it closed ' ' Now we have to update the screen ' SELECT CASE Shift CASE 1 PRINT #main.tot1, NewVal CASE 2 PRINT #main.tot2, NewVal CASE 3 PRINT #main.tot3, NewVal CASE 4 PRINT #main.tot4, NewVal CASE 5 PRINT #main.tot5, NewVal CASE 6 PRINT #main.tot6, NewVal CASE ELSE PRINT #main.tot7, NewVal END SELECT END FUNCTION
FUNCTION FN.ShowTotals()
PRINT #main.tot1, Totals(0, 1) 'display today's totals PRINT #main.tot2, Totals(0, 2) PRINT #main.tot3, Totals(0, 3) PRINT #main.tot4, Totals(0, 4) PRINT #main.tot5, Totals(0, 5) PRINT #main.tot6, Totals(0, 6) PRINT #main.tot7, Totals(0, 7)
END FUNCTION
'-------------------------------------- '--------------------------------------
FUNCTION FN.WriteData()
NumBytes = 0 FIELD #DataFile, 8 AS Buff Buff = ProcYY * 100 + TodayDD 'date format = yydd (numeric) PUT #DataFile, 1 'store today's date (rec #1)
Buff = 0 FOR I = 2 TO 8 'today's data is in recs 2 - 8 PUT #DataFile, I 'reset the current display data to 0's NEXT I
NumBytes = LOF(#DataFile) 'CALL BACKUP.DATA 'backup once each day
CLOSE #DataFile 'keep it closed, just in case...
FN.WriteData = NumBytes END FUNCTION
'-------------------------------------- '--------------------------------------
FUNCTION FN.IsFolder(Path$) '#################################################### ' MKDIR() Creates a directory. If successful the ' return value is zero. If the directory is present ' the function returns a DOS error '####################################################
IsDirectory = 0 IsDirectory = MKDIR(Path$) IF IsDirectory > 0 THEN IsDirectory = 2 ELSE IsDirectory = 1 FN.IsFolder = IsDirectory END FUNCTION
'-------------------------------------- '--------------------------------------
FUNCTION FN.OpenFile(Path$)
Fname$ = "" Fpath$ = ""
DlmPos = 0 RetVal = 0
DlmPos = FN.InstrBack(Path$, "\") Fpath$ = LEFT$(Path$, DlmPos) Fname$ = MID$(Path$, DlmPos + 1) RetVal = FN.FileExists(Fpath$, Fname$)
'IF RetVal = 0 THEN ' EXIT FUNCTION 'END IF
OPEN Path$ FOR RANDOM AS #DataFile LEN = 8
IF RetVal = 0 THEN CALL MSG "SUCCES", "File " + Path$ + " was successfully created." END IF
FN.OpenFile = 1 END FUNCTION
'-------------------------------------- '--------------------------------------
FUNCTION FN.InstrBack(TxtIn$, MatchStr$) '################################################## ' Find a match looking from end of string to ' front of string. ' 'ARGUMENTS: ' TxtIn$: Text in which to find a match. ' MatchStr$: Text to look for in "TxtIn$". ' ' NOTES: The search is NOT case sensitive. '##################################################
MatchLen = 0 TxtLen = 0 SrchPos = 0 SrchFnd = 0
TxtIn$ = UPPER$(TxtIn$) MatchStr$ = UPPER$(MatchStr$)
MatchLen = LEN(MatchStr$) TxtLen = LEN(TxtIn$) SrchPos = TxtLen
[NXT.SRCH] SrchFnd = INSTR(TxtIn$, MatchStr$, SrchPos)
IF SrchFnd = 0 THEN SrchPos = SrchPos - MatchLen
IF SrchPos <= 0 THEN EXIT FUNCTION
GOTO [NXT.SRCH] END IF
FN.InstrBack = SrchFnd END FUNCTION
'-------------------------------------------------------------- '--------------------------------------------------------------
FUNCTION FN.FileExists(FilPath$, FileName$)
DIM FILEINFO$(1, 1)
Path$ = FilPath$ + FileName$
FILES FilPath$, FileName$, FILEINFO$()
IF VAL(FILEINFO$(0, 0)) < 1 THEN CALL MSG "FILE ERROR", "File " + Path$ + " was not found!" EXIT FUNCTION END IF
FN.FileExists = 1 END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.GetData()
RecNo = 0
NumFileBytes = LOF(#DataFile) IF NumFileBytes < 1 THEN CALL MSG "FILE ERROR", "File " + Path$ + " has no data." CLOSE #DataFile EXIT FUNCTION END IF
ON ERROR GOTO [GET.DATA.ERROR] FIELD #DataFile, 8 AS Buff 'each rec is 1 8-byte, numeric value
GET #DataFile, 1 ' ' Just in case the data file has the old date format ' IF Buff < 10 THEN Buff = VAL(RIGHT$(Today$, 2)) * 100 _ + VAL(MID$(Today$, 4, 2)) 'new date format=yydd ' Totals(0, 0) = Buff 'get processing date ProcYY = INT(Buff / 100) 'get processing year ProcDD = Buff - ProcYY * 100 'get processing day FOR I = 0 TO 12 FOR J = 1 TO 7 RecNo = I * 7 + J + 1 GET #DataFile, RecNo Totals(I, J) = Buff 'if i = 0 then notice "disk" + CR$ + str$(Buff) + CR$ + str$(j) '~~~~~~~~~~~~~ NEXT J NEXT I
[GET.DATA.ERROR] CLOSE #DataFile FN.GetData = NumFileBytes END FUNCTION
'----------------------------------------------- '-----------------------------------------------
FUNCTION FN.NewYear()
RetVal = 0
IF Totals(0, 0) THEN ItsNewYear = -1 'declare a new year CALL REPORT.BUTTON "#main.totBut"'GOSUB [RptButClick1] 'create final totals rpt for last year END IF ItsNewYear = 0 'in case rpt btn gets clicked again
RetVal = FN.OpenFile(FileName$) 'GOSUB [OpenFile]
FIELD #DataFile, 8 AS Buff Buff = 0 FOR I = 1 TO 92 'set all totals to 0 RecNo = I PUT #DataFile, RecNo NEXT I ' ' Store the date as YY * 100 + dd ' ProcYY = VAL(RIGHT$(Today$, 2)) ProcDD = VAL(MID$(Today$, 4, 2)) Buff = ProcYY * 100 + ProcDD PUT #DataFile, 1 'store today's date
CLOSE #DataFile
END FUNCTION 'Template$ = "########" 'Year$ = LEFT$(Date$("yyyy/mm/dd"), 4) 'Head$ = "Shift: 9 10 11 12 1 2 Other Total" 'ReportFile$ = FilePath$ + Year$ + "_Totals.txt"
'IF ItsNewYear THEN Year$ = STR$(VAL(Year$) - 1)
'OPEN ReportFile$ FOR OUTPUT AS #Rpt 'PRINT #Rpt, "(" + ReportFile$ + ")" 'PRINT #Rpt, NULL$ 'PRINT #Rpt, NULL$ 'PRINT #Rpt, " Drive-Up Totals Report "; Date$() 'PRINT #Rpt, NULL$ 'PRINT #Rpt, NULL$ 'PRINT #Rpt, Head$ 'PRINT #Rpt, NULL$ ' ' print a month per row while summing the month total ' 'RowTot = 0 'FOR I = 1 TO 12 ' PRINT #Rpt, Month$(I); ' FOR J = 1 TO 7 ' RowTot = RowTot + Totals(I, J) 'build a row total ' PRINT #Rpt, USING(Template$, Totals(I, J)); ' NEXT J ' PRINT #Rpt, USING(Template$, RowTot) ' PRINT #Rpt, NULL$ ' RowTot = 0 'NEXT I 'CLOSE #Rpt
'IF NOT(ItsNewYear) THEN ' RetVal = FN.ShowRpt() 'END IF
'END FUNCTION
'----------------------------------------------- '-----------------------------------------------
FUNCTION FN.GenerateReport()
Template$ = "########" Head$ = "Shift: 9 10 11 12 1 2 Other Total" ReportFile$ = FilePath$ + Year$ + "_Totals.txt"
Year$ = LEFT$(Date$("yyyy/mm/dd"), 4)
IF ItsNewYear THEN Year$ = STR$(VAL(Year$) - 1)
OPEN ReportFile$ FOR OUTPUT AS #Rpt PRINT #Rpt, "(" + ReportFile$ + ")" PRINT #Rpt, NULL$ PRINT #Rpt, NULL$ PRINT #Rpt, " Drive-Up Totals Report "; Date$() PRINT #Rpt, NULL$ PRINT #Rpt, NULL$ PRINT #Rpt, NULL$ PRINT #Rpt, NULL$ ' ' print a month per row while summing the month total ' RowTot = 0 FOR I = 1 TO 12 PRINT #Rpt, Month$(I); FOR J = 1 TO 7 RowTot = RowTot + Totals(I, J) 'build a row total PRINT #Rpt, USING(Template$, Totals(I, J)); NEXT J PRINT #Rpt, USING(Template$, RowTot) PRINT #Rpt, NULL$ RowTot = 0 NEXT I
CLOSE #Rpt
IF NOT(ItsNewYear) THEN 'GOSUB [ShowRpt] RetVal = FN.ShowRpt() END IF
FN.GenerateReport = 1 END FUNCTION
'----------------------------------------------- '-----------------------------------------------
FUNCTION FN.ShowRpt()
Fpath$ = "" Fname$ = ""
Dlm = 0 Dlm = FN.InstrBack(ReportFile$, "\")
IF Dlm = 0 THEN EXIT FUNCTION
Fpath$ = LEFT$(ReportFile$, Dlm) Fname$ = MID$(ReportFile$, Dlm + 1) Dlm = FN.FileExists(Fpath$, Fname$)
IF Dlm = 0 THEN EXIT FUNCTION
WindowWidth = 750 'sized so rpt just fits WindowHeight = 800 UpperLeftX = UpperLeftX + 550 'this window is right of the main UpperLeftY = UpperLeftY - 200 'slightly higher than the main
IF RptWinOpen THEN CLOSE #RptWin 'make sure it isn't already open
OPEN "Drive-Up Report" FOR text_nsb AS #RptWin 'open a new window RptWinOpen = 1 #RptWin, "!font consolas 14" 'use mono-spaced typeface so columns align
OPEN ReportFile$ FOR INPUT AS #Rpt WHILE NOT (EOF(#Rpt)) LINE INPUT #Rpt, Line$ PRINT #RptWin, Line$ 'copy each line from the rpt file to the new window WEND CLOSE #Rpt
END FUNCTION
'------------------------------------------------------------ '------------------------------------------------------------
FUNCTION FN.CreateCountWin()
SS.CENTER = HEXDEC("&H00000001") SS.CENTERIMAGE = HEXDEC("&H00000200")
WindowWidth = 750 WindowHeight = 600 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "white"
statictext #main.label1, "Drive-Up Window Log", 10, 5, 400, 35 statictext #main.label2, date$(), 10, 60, 200, 30 STYLEBITS #main.Time, SS.CENTER OR SS.CENTERIMAGE, 0, 0, 0 STATICTEXT #main.Time, TIME$(), 220, 60, 85, 30 statictext #main.label3, "Shift", 10, 125, 100, 25 statictext #main.label4, "1. 9:00", 10, 160, 100, 25 statictext #main.label5, "2. 10:00", 10, 210, 100, 25 statictext #main.label6, "3. 11:00", 10, 260, 100, 25 statictext #main.label7, "4. 12:00", 10, 310, 100, 25 statictext #main.label8, "5. 1:00", 10, 360, 100, 25 statictext #main.label9, "6. 2:00", 10, 410, 100, 25 statictext #main.label10, "Other", 10, 460, 100, 25 ' ' set up total boxes as static text so users can't change them ' use stylebits to add borders to the boxes ' statictext #main.tot1, "0", 130, 160, 40, 30 stylebits #main.tot1, _WS_BORDER, 0, 0, 0 statictext #main.tot2, "0", 130, 210, 40, 30 stylebits #main.tot2, _WS_BORDER, 0, 0, 0 statictext #main.tot3, "0", 130, 260, 40, 30 stylebits #main.tot3, _WS_BORDER, 0, 0, 0 statictext #main.tot4, "0", 130, 310, 40, 30 stylebits #main.tot4, _WS_BORDER, 0, 0, 0 statictext #main.tot5, "0", 130, 360, 40, 30 stylebits #main.tot5, _WS_BORDER, 0, 0, 0 statictext #main.tot6, "0", 130, 410, 40, 30 stylebits #main.tot6, _WS_BORDER, 0, 0, 0 statictext #main.tot7, "0", 130, 460, 40, 30 stylebits #main.tot7, _WS_BORDER, 0, 0, 0 ' ' set up bmp buttons - no other way to get colored buttons ' & couldn't get logo to work otherwise ' RADIOBUTTON #main.greenBut, "ADD", BUTTON.CLICK, BUTTON.CLICK, 260, 200, 45, 20 RADIOBUTTON #main.redBut, "DELETE", BUTTON.CLICK, BUTTON.CLICK, 260, 350, 45, 20 GRAPHICBOX #main.logo, 560, 2, 45, 20
BUTTON #main.totBut, "Totals Report", REPORT.BUTTON, UL, 590, 475, 110, 35 ' ' This next button doesn't do anything, but we need it to take focus ' to avoid the strange behavior of treating the last button clicked ' as the default so that it fires if the users presses Enter or spacebar ' 'button #main.dummy, "", [LogoButClick], UL, 580, 475, 0, 0 'dummy button
'-----End GUI objects definitions
OPEN "Drive-Up Log" FOR window AS #main 'open the window '#main, "font arial 14" #main.label1, "!font arial_bold 18" #main.label2, "!font arial_bold 16" #main.Time, "!FONT ARIAL_BOLD 16" #main.totBut, "!font arial_narrow 14"
#main.tot1, "!font arial_bold 14" #main.tot2, "!font arial_bold 14" #main.tot3, "!font arial_bold 14" #main.tot4, "!font arial_bold 14" #main.tot5, "!font arial_bold 14" #main.tot6, "!font arial_bold 14" #main.tot7, "!font arial_bold 14" #main.logo, "disable" #main, "trapclose END.LOG"
PRINT #main.logo, "BACKCOLOR BLUE" PRINT #main.logo, "DOWN" PRINT #main.logo, "FILL BLUE" PRINT #main.logo, "FLUSH" PRINT #main.logo, "DISCARD" END FUNCTION
|
|