Example use of "FirstTime" library function: GUI i
Posted: 10 March 2015, 23:47 PM
I have found the "FirstTime" Library function (which returns True the first time it is called after a program download, otherwise False) very useful in an application (MahYong score calculator) where an educational but rather lengthy start-up message about the use of a device only needs to be shown a few times for novice users, after which the message can be skipped since the user is assumed to be sufficiently knowledgeable and only the short welcome greeting needs to be shown.
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.
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