home *** CD-ROM | disk | FTP | other *** search
/ distrib.akp.su/Programming/Vb-6+Rus/ / distrib.akp.su.tar / distrib.akp.su / Programming / Vb-6+Rus / VB98 / TEMPLATE / FORMS / TIPOFDAY.FRM (.txt) < prev    next >
Visual Basic Form  |  1998-06-18  |  5KB  |  153 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTip 
  3.    Caption         =   "Tip of the Day"
  4.    ClientHeight    =   3285
  5.    ClientLeft      =   2370
  6.    ClientTop       =   2400
  7.    ClientWidth     =   5415
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    MinButton       =   0   'False
  11.    ScaleHeight     =   3285
  12.    ScaleWidth      =   5415
  13.    WhatsThisButton =   -1  'True
  14.    WhatsThisHelp   =   -1  'True
  15.    Begin VB.CheckBox chkLoadTipsAtStartup 
  16.       Caption         =   "&Show Tips at Startup"
  17.       Height          =   315
  18.       Left            =   120
  19.       TabIndex        =   3
  20.       Top             =   2940
  21.       Width           =   2055
  22.    End
  23.    Begin VB.CommandButton cmdNextTip 
  24.       Caption         =   "&Next Tip"
  25.       Height          =   375
  26.       Left            =   4080
  27.       TabIndex        =   2
  28.       Top             =   600
  29.       Width           =   1215
  30.    End
  31.    Begin VB.PictureBox Picture1 
  32.       BackColor       =   &H00FFFFFF&
  33.       Height          =   2715
  34.       Left            =   120
  35.       Picture         =   "Tip of the Day.frx":0000
  36.       ScaleHeight     =   2655
  37.       ScaleWidth      =   3675
  38.       TabIndex        =   1
  39.       Top             =   120
  40.       Width           =   3735
  41.       Begin VB.Label Label1 
  42.          BackColor       =   &H00FFFFFF&
  43.          Caption         =   "Did you know..."
  44.          Height          =   255
  45.          Left            =   540
  46.          TabIndex        =   5
  47.          Top             =   180
  48.          Width           =   2655
  49.       End
  50.       Begin VB.Label lblTipText 
  51.          BackColor       =   &H00FFFFFF&
  52.          Height          =   1635
  53.          Left            =   180
  54.          TabIndex        =   4
  55.          Top             =   840
  56.          Width           =   3255
  57.       End
  58.    End
  59.    Begin VB.CommandButton cmdOK 
  60.       Cancel          =   -1  'True
  61.       Caption         =   "OK"
  62.       Default         =   -1  'True
  63.       Height          =   375
  64.       Left            =   4080
  65.       TabIndex        =   0
  66.       Top             =   120
  67.       Width           =   1215
  68.    End
  69. Attribute VB_Name = "frmTip"
  70. Attribute VB_GlobalNameSpace = False
  71. Attribute VB_Creatable = False
  72. Attribute VB_PredeclaredId = True
  73. Attribute VB_Exposed = False
  74. Option Explicit
  75. ' The in-memory database of tips.
  76. Dim Tips As New Collection
  77. ' Name of tips file
  78. Const TIP_FILE = "TIPOFDAY.TXT"
  79. ' Index in collection of tip currently being displayed.
  80. Dim CurrentTip As Long
  81. Private Sub DoNextTip()
  82.     ' Select a tip at random.
  83.     CurrentTip = Int((Tips.Count * Rnd) + 1)
  84.     ' Or, you could cycle through the Tips in order
  85. '    CurrentTip = CurrentTip + 1
  86. '    If Tips.Count < CurrentTip Then
  87. '        CurrentTip = 1
  88. '    End If
  89.     ' Show it.
  90.     frmTip.DisplayCurrentTip
  91. End Sub
  92. Function LoadTips(sFile As String) As Boolean
  93.     Dim NextTip As String   ' Each tip read in from file.
  94.     Dim InFile As Integer   ' Descriptor for file.
  95.     ' Obtain the next free file descriptor.
  96.     InFile = FreeFile
  97.     ' Make sure a file is specified.
  98.     If sFile = "" Then
  99.         LoadTips = False
  100.         Exit Function
  101.     End If
  102.     ' Make sure the file exists before trying to open it.
  103.     If Dir(sFile) = "" Then
  104.         LoadTips = False
  105.         Exit Function
  106.     End If
  107.     ' Read the collection from a text file.
  108.     Open sFile For Input As InFile
  109.     While Not EOF(InFile)
  110.         Line Input #InFile, NextTip
  111.         Tips.Add NextTip
  112.     Wend
  113.     Close InFile
  114.     ' Display a tip at random.
  115.     DoNextTip
  116.     LoadTips = True
  117. End Function
  118. Private Sub chkLoadTipsAtStartup_Click()
  119.     ' save whether or not this form should be displayed at startup
  120.     SaveSetting App.EXEName, "Options", "Show Tips at Startup", chkLoadTipsAtStartup.Value
  121. End Sub
  122. Private Sub cmdNextTip_Click()
  123.     DoNextTip
  124. End Sub
  125. Private Sub cmdOK_Click()
  126.     Unload Me
  127. End Sub
  128. Private Sub Form_Load()
  129.     Dim ShowAtStartup As Long
  130.     ' See if we should be shown at startup
  131.     ShowAtStartup = GetSetting(App.EXEName, "Options", "Show Tips at Startup", 1)
  132.     If ShowAtStartup = 0 Then
  133.         Unload Me
  134.         Exit Sub
  135.     End If
  136.         
  137.     ' Set the checkbox, this will force the value to be written back out to the registry
  138.     Me.chkLoadTipsAtStartup.Value = vbChecked
  139.     ' Seed Rnd
  140.     Randomize
  141.     ' Read in the tips file and display a tip at random.
  142.     If LoadTips(App.Path & "\" & TIP_FILE) = False Then
  143.         lblTipText.Caption = "That the " & TIP_FILE & " file was not found? " & vbCrLf & vbCrLf & _
  144.            "Create a text file named " & TIP_FILE & " using NotePad with 1 tip per line. " & _
  145.            "Then place it in the same directory as the application. "
  146.     End If
  147. End Sub
  148. Public Sub DisplayCurrentTip()
  149.     If Tips.Count > 0 Then
  150.         lblTipText.Caption = Tips.Item(CurrentTip)
  151.     End If
  152. End Sub
  153.