11-10-2022, 03:35 PM
Hey Pete, here's a little proof of concept for your golf score card project. I didn't have your background image file so I just focused on the mechanics of what I think you are trying to achieve.
As you enter the scores the total field is updated automatically. Clicking the Save Scores button will add the current set of scores to the saved score list. This list will be saved to the browser's local storage as well as to a "scores.csv" file in the QBJS virtual file system. You can access this in the Files tab of the Console.
View in QBJS
As you enter the scores the total field is updated automatically. Clicking the Save Scores button will add the current set of scores to the saved score list. This list will be saved to the browser's local storage as well as to a "scores.csv" file in the QBJS virtual file system. You can access this in the Files tab of the Console.
Code: (Select All)
Import Dom From "lib/web/dom.bas"
Import Storage From "lib/web/storage.bas"
Dim Shared savedScores As String
Dim Shared scores(10) As Object
_Title "Pete's Front Nine"
' Load the saved scores from local browser storage
savedScores = Storage.Get("savedScores")
Print savedScores
RefreshSavedScores
' Create the containing div
Dim div: div = Dom.Create("div")
div.style.backgroundColor = "#ccc"
div.style.padding = "20px"
' Create the inputs
Dim i As Integer
For i = 1 To 10
scores(i) = Dom.Create("input", div)
scores(i).tabIndex = i
scores(i).type = "number"
scores(i).style.width = "40px"
scores(i).style.marginRight = "2px"
If i = 10 Then
scores(i).disabled = true
Else
Dom.Event scores(i), "change", sub_UpdateScore
End If
Next i
Dim btn As Object
Dom.Create "br", div
Dom.Create "br", div
btn = Dom.Create("button", div, "Save Scores")
Dom.Event btn, "click", sub_SaveScores
' Updates the total when one of the scores is changed
Sub UpdateScore
Dim total As Integer
Dim i As Integer
For i = 1 To 9
total = total + CInt(scores(i).value)
Next i
scores(10).value = total
End Sub
' Saves the scores when the button is clicked
Sub SaveScores
If savedScores <> "" Then
savedScores = savedScores + Chr$(10)
End If
savedScores = savedScores + Date$ + " " + Time$
Dim i As Integer
For i = 1 To 10
savedScores = savedScores + ", " + scores(i).value
scores(i).value = ""
Next i
' Save the scores to the browser's local storage
Storage.Set "savedScores", savedScores
' Save the scores to the QBJS virtual file system
Open "scores.csv" For Output As #1
Print #1, savedScores
Close #1
RefreshSavedScores
End Sub
' Refreshes the saved score display
' Using the main QB screen for testing
Sub RefreshSavedScores
Cls
Print "Saved Scores"
Print "--------------------------------------------------------"
Print savedScores
End Sub
View in QBJS