In the following code excerpt a class "DisplayGUI" has a constructor in which a counter is managed whose task is to keep track of how often the class has been called after a program download. The first time after download the counter (in persistent EEPROM memory) is set to a predefined value, subsequent calls will decrement its value if it is larger than zero.
The class method "ShownEnoughTimes" returns False if the counter is non-zero, True otherwise, and can be used by the application. This method is then used in the "Greeting" method which prints the start-up message, which may be long or short depending on the download history. No user intervention is needed.
Code: Select all
Class DisplayGUI
Private Const DownloadCounterAddress as Integer = 100
Private Const maxIntro as Byte = 10
Dim downloadStatus as Byte
Public Sub _Create()
If FirstTime Then
Call PersistentPoke(maxIntro,DownloadCounterAddress)
Else
downloadStatus = PersistentPeek(DownloadCounterAddress)
If downloadStatus > 0 then
downloadStatus = downloadStatus - 1
Call PersistentPoke(downloadStatus,DownloadCounterAddress)
End If
End If
End Sub
Public Function ShownEnoughTimes() as Boolean
downloadStatus = PersistentPeek(DownloadCounterAddress)
If downloadStatus > 0 Then
ShownEnoughTimes = False
Else
ShownEnoughTimes = True
End If
End Function
' ...
' ...
' Public method for start-up message:
Public Sub Greeting()
If Not ShownEnoughTimes Then
'Generate introductory & educational message here
End If
'Standard greeting message here
End Sub
End Class