home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / MyPSCDownl2013028132006.psc / frmSplash.frm < prev    next >
Text File  |  2006-08-13  |  7KB  |  232 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSplash 
  3.    Caption         =   "My PSC Downloads"
  4.    ClientHeight    =   2700
  5.    ClientLeft      =   60
  6.    ClientTop       =   450
  7.    ClientWidth     =   5355
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2700
  10.    ScaleWidth      =   5355
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.Label Label2 
  13.       Caption         =   "By Clive Astley"
  14.       Height          =   255
  15.       Left            =   120
  16.       TabIndex        =   4
  17.       Top             =   1920
  18.       Width           =   3375
  19.    End
  20.    Begin VB.Label Label1 
  21.       Caption         =   "clive.astley@kingswoodaccounting.co.uk"
  22.       Height          =   255
  23.       Left            =   120
  24.       TabIndex        =   3
  25.       Top             =   2160
  26.       Width           =   3375
  27.    End
  28.    Begin VB.Label lblWait 
  29.       Caption         =   "Please wait whilst MyPSCDownloads is prepared"
  30.       BeginProperty Font 
  31.          Name            =   "MS Sans Serif"
  32.          Size            =   13.5
  33.          Charset         =   0
  34.          Weight          =   400
  35.          Underline       =   0   'False
  36.          Italic          =   0   'False
  37.          Strikethrough   =   0   'False
  38.       EndProperty
  39.       Height          =   735
  40.       Left            =   120
  41.       TabIndex        =   2
  42.       Top             =   240
  43.       Width           =   4695
  44.    End
  45.    Begin VB.Label lblRecords 
  46.       Height          =   255
  47.       Left            =   2160
  48.       TabIndex        =   1
  49.       Top             =   1200
  50.       Width           =   1335
  51.    End
  52.    Begin VB.Label lblImporting 
  53.       Caption         =   "Populating the database"
  54.       Height          =   255
  55.       Left            =   120
  56.       TabIndex        =   0
  57.       Top             =   1200
  58.       Width           =   1815
  59.    End
  60. End
  61. Attribute VB_Name = "frmSplash"
  62. Attribute VB_GlobalNameSpace = False
  63. Attribute VB_Creatable = False
  64. Attribute VB_PredeclaredId = True
  65. Attribute VB_Exposed = False
  66. Option Explicit
  67.   Dim strDatabaseName As String
  68.   Dim strFilePattern As String
  69.   Dim strPscDirectory As String
  70.   Dim db As Database
  71.   Dim strSQL As String
  72.  
  73. Private Sub Form_Load()
  74.  
  75.   strDatabaseName = "MyPSCDownloads.mdb"
  76.   strPscDirectory = "D:\MyPSCDownloadLibrary\" 'Where downloads are stored
  77.   strFilePattern = "@PSC*.txt"
  78.  
  79.   If Right$(App.Path, 1) = "\" Then
  80.     strDatabasePath = App.Path & strDatabaseName
  81.   Else
  82.     strDatabasePath = App.Path & "\" & strDatabaseName
  83.   End If
  84.  
  85.   Set db = OpenDatabase(strDatabasePath)
  86.   
  87.   strSQL = "DELETE From MainTable"  'Empties the database
  88.   db.Execute strSQL
  89.    
  90.   db.Close
  91.   Call Compact  'Compacts the database to reset autonumber ID
  92.    
  93.   Me.Show
  94.   'MsgBox "Emptied"
  95.   DoEvents
  96.  
  97.   Call FindFiles(strPscDirectory, strFilePattern)
  98.  
  99.   frmMainForm.Show
  100.   Unload Me
  101.  
  102. End Sub
  103.  
  104. 'FINDFILE FUNCTION FROM ROD STEPHENS BOOK
  105. '(my one modification to call ReadFile() is annotated below
  106. 'This extracts all the PSC Readme .txt files from the Download directory
  107. Private Function FindFiles(ByVal start_dir As String, ByVal file_pattern As String) As String
  108.   Dim dirs() As String
  109.   Dim num_dirs As Long
  110.   Dim sub_dir As String
  111.   Dim file_name As String
  112.   Dim i As Integer
  113.   Dim txt As String
  114.  
  115.   file_name = Dir$(start_dir & file_pattern, vbNormal)
  116.   Do While Len(file_name) > 0
  117.     txt = txt & start_dir & file_name & vbCrLf
  118.     file_name = Dir$(, vbNormal)
  119.   Loop
  120.  
  121.   sub_dir = Dir$(start_dir & "*", vbDirectory)
  122.   Do While Len(sub_dir) > 0
  123.     If UCase$(sub_dir) <> "PAGEFILE.SYS" And _
  124.       sub_dir <> "." And sub_dir <> ".." _
  125.     Then
  126.       sub_dir = start_dir & sub_dir
  127.         If GetAttr(sub_dir) And vbDirectory Then
  128.           num_dirs = num_dirs + 1
  129.           ReDim Preserve dirs(1 To num_dirs)
  130.           dirs(num_dirs) = sub_dir & "\"
  131.         End If
  132.         End If
  133.  
  134.       sub_dir = Dir$(, vbDirectory)
  135.   Loop
  136.  
  137.   For i = 1 To num_dirs
  138.     txt = txt & FindFiles(dirs(i), file_pattern)
  139.     'THE NEXT THREE LINES IS MY ONLY MODIFICATION
  140.     frmSplash.lblRecords.Caption = i
  141.     DoEvents
  142.     Call ReadFile(FindFiles(dirs(i), file_pattern))
  143.   Next i
  144.  
  145.   FindFiles = txt
  146.   
  147. End Function
  148.  
  149. Private Sub ReadFile(ByVal strFileName As String)
  150.   Dim strTextToCheck As String
  151.   Dim lngPosTitle As Long
  152.   Dim lngPosTitleCrlf As Long
  153.   Dim lngPosDescription As Long
  154.   Dim lngPosDescriptionCrlf As Long
  155.   Dim lngPosHTTP As Long
  156.   Dim lngPosHTTPcrlf As Long
  157.   Dim lngFileListDir As Long
  158.   Dim strWeb As String
  159.   Dim strTitle As String
  160.   Dim strDescription As String
  161.   Dim strFileListDir As String
  162.   Dim strSQL As String
  163.   
  164.   Set db = OpenDatabase(strDatabasePath)
  165.   
  166.       Dim rs As Recordset
  167.       Set rs = db.OpenRecordset("MainTable")
  168.   
  169.   If strFileName <> "" Then
  170.     strFileName = Left$(strFileName, Len(strFileName) - 2) 'Removes 2 non-displayable characters at end
  171.     strTextToCheck = FileContents(strFileName)
  172.  
  173.     lngPosTitle = InStr(strTextToCheck, "Title")
  174.     lngPosTitleCrlf = InStr(lngPosTitle, strTextToCheck, vbCrLf)
  175.     strTitle = Mid$(strTextToCheck, lngPosTitle, (lngPosTitleCrlf - lngPosTitle)) & " "
  176.     
  177.     lngPosDescription = InStr(strTextToCheck, "Description")
  178.     lngPosDescriptionCrlf = InStr(lngPosDescription, strTextToCheck, vbCrLf)
  179.     strDescription = Mid$(strTextToCheck, lngPosDescription, (lngPosDescriptionCrlf - lngPosDescription))
  180.     
  181.     lngPosHTTP = InStr(strTextToCheck, "http")
  182.     lngPosHTTPcrlf = InStr(lngPosHTTP, strTextToCheck, vbCrLf)
  183.     strWeb = Mid$(strTextToCheck, lngPosHTTP, (lngPosHTTPcrlf - lngPosHTTP))
  184.     
  185.     lngFileListDir = InStr(strFileName, "\")
  186.     lngFileListDir = InStr(lngFileListDir + 1, strFileName, "\")
  187.     lngFileListDir = InStr(lngFileListDir + 1, strFileName, "\")
  188.     strFileListDir = Left$(strFileName, lngFileListDir)
  189.     
  190.     rs.AddNew
  191.     rs("Title") = strTitle
  192.     rs("Description") = strDescription
  193.     rs("Web") = strWeb
  194.     rs("FileName") = strFileName
  195.     rs("FileListDir") = strFileListDir
  196.     rs.Update
  197.        
  198.   End If
  199.     
  200. End Sub
  201.  
  202. 'THIS FUNCTION FROM ROD STEPHENS BOOK
  203. Private Function FileContents(ByVal filename As String) As String
  204.   Dim fnum As Integer
  205.  
  206.   On Error GoTo OpenError
  207.   fnum = FreeFile
  208.   Open filename For Input As fnum
  209.   FileContents = Input$(LOF(fnum), #fnum)
  210.   Close fnum
  211.   Exit Function
  212.  
  213. OpenError:
  214.     MsgBox "Error " & Format$(Err.Number) & _
  215.       " reading file." & vbCrLf & _
  216.         Err.Description
  217.   Exit Function
  218. End Function
  219.  
  220. Private Sub Compact()
  221. Dim db_name As String
  222. Dim temp_name As String
  223.  
  224.     db_name = strDatabasePath
  225.     temp_name = db_name & ".temp"
  226.     DAO.DBEngine.CompactDatabase db_name, temp_name
  227.     Kill db_name
  228.     Name temp_name As db_name
  229.  
  230. End Sub
  231.  
  232.