' Load the next tip from the tip file.
Private Function NextTip() As String
Dim offset_string As Integer
Dim offset As Integer
Dim tip_text As String
' Read the registry to get the byte offset for
' the next tip in the tips file.
offset_string = GetSetting("TipOfTheDay", _
"Parameters", "NextOffset", "1")
offset = CInt(offset_string)
' Get the tip.
tip_text = TipAtOffset(offset)
' If the tip is blank, get the first tip.
If tip_text = "" Then tip_text = TipAtOffset(1)
NextTip = tip_text
End Function
' Load the indicated tip from the tip file.
Private Function TipAtOffset(ByVal offset As Integer) As _
String
Const MAX_TIP_LENGTH = 256
Dim fnum As Integer
Dim tip_buffer As String * MAX_TIP_LENGTH
Dim tip_text As String
Dim pos As Integer
' Open the tip file and read the next
' MAX_TIP_LENGTH bytes.
fnum = FreeFile
Open App.Path & "\tips.txt" For Binary As fnum
Get #fnum, offset, tip_buffer
Close fnum
' Find the end of the tip.
tip_text = Trim$(tip_buffer)
pos = InStr(tip_text, vbCrLf)
If pos = 0 Then
offset = 1
tip_text = ""
Else
tip_text = Left$(tip_text, pos - 1)
offset = offset + pos + 1
End If
TipAtOffset = tip_text
' Save the offset for the next tip.
SaveSetting "TipOfTheDay", _
"Parameters", "NextOffset", offset
End Function
Private Sub cmdNextTip_Click()
lblTip.Caption = NextTip
End Sub
Private Sub Form_Load()
lblTip.Caption = NextTip
End Sub
|