Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitlePresent a tip-of-the-day
DescriptionThis example shows how to present a tip-of-the-day in Visual Basic 6. It uses the Registry to keep track of which tips it has displayed.
Keywordstotd, tip of the day, tip-of-the-day
CategoriesFiles and Directories, Software Engineering
 
Put the tips in a text file ending in a blank line. Store the byte offset of the next tip in the registry. Initially this should be blank or 1. To load a tip, fetch this offset from the registry. Read data from the file starting at that offset. Find the next vbCrLf and save that position as the next offset.
 
' 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated