hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 25, 2022 17:56:29 GMT -5
Hi, First project for my local library. I created a very simple program at home. Tested it and then installed it at the library. They experience a problem with it that I can't reproduce at home. There is a button that is used to increment a counter. When the counter has a value of 0, sometimes clicking the button updates the counter to 4 instead of 1. This never happens at home. I've made a few updates, but they are still seeing this semi-random problem.
1. Am I correct that to update the app at the library all I need to do is to create a tkn file at home and then copy it to the right folder at the library?
2. Are there any environmental issues that might cause a LB program to behave differently at the library than at my house? Both sides running some flavor of Win 10.
Thanks for any wisdom you can share.
|
|
|
Post by Brandon Parker on Aug 25, 2022 18:14:57 GMT -5
The answer to question #1 is: Yes, you are correct. As long as the Runtime Engine version at the library is from the same version of Liberty BASIC that you are using to compile the TKN file at your home, all you have to do is take the TKN file to the library computer where your program runs.
The answer to question #2 is not so simple. It really depends, but IMO, things tend to perform similarly across the same Windows major version.
You can share the program here or privately over PM if you would like. I would be more than happy to take a look at it and see if anything stands out.
{:0)
Brandon Parker
|
|
hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 25, 2022 19:28:22 GMT -5
Thank you so much Brandon. If I can figure out how to do it I'm happy to post it here.
' DRIVEUP.BAS 8/6/22 Hal Pryor ' ' Keep track of the transactions at the Drive Up window at PV Library ' NOMAINWIN ON ERROR GOTO [ErrorHandler] DIM Totals(12, 7) 'month, shift DIM Mon$(12) 'load array with month names CR$ = CHR$(13) 'ascii carriage RETURN Null$ = "" 'ascii null ItsNewYear = 0 'prob not a new year RptWinOpen = 0 'is the rpt window open? Today$ = Date$("mm/dd/yy") TodayDD = VAL(MID$(Today$, 4, 2)) 'day number
MonthNames$ = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" FOR i = 1 TO 12 Mon$(i) = WORD$(MonthNames$, i) NEXT i
TIMER 21600000, [Quit.main] 'set timer for 6 hours '(in case last shift doesn't close) 'we want to restart every morning ' in case they change the hours... ' Hour1 = 9 'first shift Hour6 = 14 'last shift ' ' set up some variables for path and file names ' FilePath$ = "C:\DriveUpLog\" FileName$ = FilePath$ + "DriveUp.dat" DevPath$ = FilePath$ + "Dev\" BackupName$ = FilePath$ + "DriveUpBackUp.dat" LogoSpec$ = DevPath$ + "PVLogo.bmp" Greenspec$ = DevPath$ + "greenBut.bmp" RedSpec$ = DevPath$ + "redBut.bmp"
GOSUB [OpenFile] TRACE 0 GOSUB [GetData] 'read all the data into array TRACE 2 ' ' handle new year when it's encountered - probably not all that often... ' NewYear = VAL(RIGHT$(Today$, 2)) IF NewYear <> ProcYY THEN GOSUB [NewYear] 'is this a new year?
TRACE 0 GOSUB [Setup.Main.Window] 'do all the gui setup TRACE 2 ' ' if it's today's data just display the current totals ' IF ProcDD = TodayDD THEN 'not the first time today 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) ELSE ' ' This is the first time today so do the daily stuff ' 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 GOSUB [BackUp] 'backup once each day END IF
CLOSE #DataFile 'keep it closed, just in case... WAIT 'Now WAIT for the user to click a button...
[GreenButClick] 'Perform action for the green button Adj = 1 '1 -> add GOSUB [Clicker] 'process the button click WAIT
[RedButClick] 'Perform action for the red button Adj = -1 '-1 -> subtract GOSUB [Clicker] 'process the button click WAIT
[Clicker] 'Add/subtract 1 to total and today's values #main.dummy, "!setfocus" 'keep focus off of the main buttons (or they default) 'some users like the Enter and space bar... 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) Shift = Hour - 8 'xlate hour # to shift # ' ' Update the monthly total ' 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 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 + Adj '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 RETURN
[RptButClick] 'Perform action for Totals Report GOSUB [RptButClick1] 'btn def can't do a GOSUB... WAIT
[RptButClick1] 'Create the report file Year$ = LEFT$(Date$("yyyy/mm/dd"), 4) IF ItsNewYear THEN Year$ = STR$(VAL(Year$) - 1) Template$ = "########" Head$ = "Shift: 9 10 11 12 1 2 Other Total" ReportFile$ = FilePath$ + Year$ + "_Totals.txt" 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, Mon$(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] 'not new year so show rpt RETURN
[ShowRpt] 'Display the report in a separate window 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 RETURN
[LogoButClick] 'Somebody clicked the logo - just ignore it WAIT ' ' General routines below ' [OpenFile] 'open and field the data file in ONE place OPEN FileName$ FOR RANDOM AS #DataFile LEN = 8 FIELD #DataFile, 8 AS Buff 'each rec is 1 8-byte, numeric value RETURN
[GetData] 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 RETURN
[BackUp] 'make a backup copy of the data file (first thing each AM) 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 RETURN
[NewYear] 'It's a new year: create totals rpt and init all the totals for the new year ItsNewYear = -1 'declare a new year GOSUB [RptButClick1] 'create final totals rpt for last year ItsNewYear = 0 'in case rpt btn gets clicked again
GOSUB [OpenFile]
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 RETURN
[Setup.Main.Window] 'all the gui crap 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 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 ' bmpbutton #main.greenBut, Greenspec$, [GreenButClick], UL, 260, 200 bmpbutton #main.redBut, RedSpec$, [RedButClick], UL, 260, 350 bmpbutton #main.logo, LogoSpec$, [LogoButClick], UL, 560, 2
button #main.totBut, "Totals Report", [RptButClick], 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.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 [Quit.main]" RETURN
[ErrorHandler] 'Error messages NOTICE "Error string is " + chr$(34) + Err$ + chr$(34) NOTICE "Error number is ";Err
[Quit.main] 'End the program IF RptWinOpen THEN CLOSE #RptWin 'close the report window if it's open CLOSE #main END
|
|
|
Post by Walt Decker on Aug 26, 2022 12:29:08 GMT -5
Running you code I found a few problems:
' set up some variables for path and file names ' FilePath$ = "C:\DriveUpLog\" '<--- change to DefaultDir$ + "\"
When you open a random access or binary file, if the file name is not present in the indicated directory the file IS CREATED. Therefore, you should always check to insure that the file is present BEFORE opening it. (Actually you should check with any kind of file).
FUNCTION FN.FileExists(Path$, FileName$)
DIM FileSpec$(0, 0) files Path$, FileName$, FileSpec$()
IF FileSpec$(0, 0) = 0 THEN FN.FileExists = 0 EXIT FUNCTION END IF
FN.FileExists = 1 END FUNCTION
You should always check for the size of the file. A file can exist but have no data.
[OpenFile] 'open and field the data file in ONE place OPEN FileName$ FOR RANDOM AS #DataFile LEN = 8 FIELD #DataFile, 8 AS Buff 'each rec is 1 8-byte, numeric value RETURN
[GetData] LenOFile = LOF(#DataFile) IF LenOFile < 1 THEN CLOSE #DataFile FileEmpty = 1 RETURN END IF
At label [RptButClick1] I ran into a "normalized float" run-time error.
It might be wise to break down the errors to discrete areas for better error handling and control.
|
|
|
Post by Walt Decker on Aug 26, 2022 17:09:27 GMT -5
Mr. Pryor:
If anyone other than you is to use this app it might be wise to either:
1) use named buttons as an indicator of what to push, e. g. "Add client", "Delete client" 2) include a label (static control) indicating the purpose of the buttons 3) change the "logo" button to a graphic control. That way, unless graphic statements are used, clicking on the control will do nothing and you can eliminate the branch for that button.
|
|
hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 26, 2022 17:38:56 GMT -5
tsh73, sorry, I copied the file contents into the reply area which uses proportional fonts, so the 8-byte fields got represented smaller.
Mr. Decker, thanks for the advice. The buttons are bmp buttons and the bitmap includes the instructions. It was important that one button be green and the other red. I couldn't find an easy way to do that in LB with regular buttons, so I had to go to bmp buttons.
As for the logo button, I wanted to use a graphic control, but I had never done that before and was pressed for time so I used a bmp button. Can you tell me which control I would need to use to just display a bitmap in the app window? I tried a few things, but I must have done them incorrectly. The only one that worked created a separate window.
I was wondering when somebody would notice the misuse of a button...
Thanks to all for the great advice.
|
|
|
Post by Walt Decker on Aug 27, 2022 8:42:23 GMT -5
Mr. Pryor, here you go. In the code, REM is the same as ' (single quote)'
BUTTON #main.greenBut, "GREEN", [GreenButClick], UL, 260, 200, 45, 20 BUTTON #main.redBut, "RED", [RedButClick], UL, 260, 350, 45, 20 REM remove the following REM BUTTON #main.logo, "LOGO", [LogoButClick], UL, 560, 2, 45, 20 REM replace with GRAPHICBOX #main.GFX, 560, 2, 45, 20
......... ......... ......... .........
REM remove the following REM #main.logo, "disable" REM replace with LOADBMP "LOGO", LogoSpec$ '<--- put bitmap in memory #main.GFX, "DOWN" '<--- enable drawing #main.GFX, "DRAWBMP LOGO 0 0" '<--- render the memory bitmap #main.GFX, "FLUSH" '<--- make it stick #main.GFX, "DISCARD" '<--- discard graphic instructions #main, "trapclose [Quit.main]" RETURN
PS: Did you find the double-click problem?
|
|
hal9k
Junior Member
Posts: 87
|
Post by hal9k on Aug 27, 2022 12:01:31 GMT -5
Mr. Decker, Thank you so much! I had to adjust the size and lose the border, but it works great.
Sadly, the other problem is still a mystery. It works fine for me and for you guys, but as of last week, it was randomly incrementing by values greater than 1. I am unable to explain how this can happen. I make minor changes each week and then install a new version at the library. So far, I'm still getting reports of random failures. I installed a new version that also logs a bunch of variables for each button click. I'll see results on Monday. Hopefully the problem will magically disappear, if not, at least I'll have some data to look at to try to solve the mystery.
To All, Thanks for your help and support. I do strictly volunteer work, and with all the help I've received here I now feel I have another tool in my bag to help out the small town where I live in my dotage.
|
|