home *** CD-ROM | disk | FTP | other *** search
- DefInt A-Z
- Option Explicit
-
- 'Declares for VBLIB declards
- '------------------------------------
- 'Global Variables and Constants
- '------------------------------------
- Global Routines() As String 'array of routine names
- Global Path$ 'application path
- Global OldChoice As Integer 'previously selected routine
- 'Global BigTab$ 'used for indexing sorted listbox
- Global OldChoiceChanged As Integer 'flags change in current record
- 'Global ClipCount% As Integer 'tracks number of records
-
- Global Const CodeStart$ = "[Code]" 'used in cFile$ to separate description and code
- Global Const CodeEnd$ = "[Stop]" 'end of code marker for cFile$
- '------------------------------------
- 'Module level variables used in file handling routines
- '------------------------------------
- Dim F As Integer 'file handle
- Dim J As Integer 'file handle
- Dim RecordNum As Integer 'identifies current record
-
-
-
-
- Sub CleanUpFiles ()
- Dim X%
- '------------------------------------
- 'Kill old backups
- 'Backup current files
- 'Make temp files current
- '------------------------------------
- On Error Resume Next
- Kill Path$ + "Titles.Bak"
- Kill Path$ + "ClipText.Bak"
- Name tFile$ As Path$ + "Titles.Bak"
- Name cFile$ As Path$ + "ClipText.Bak"
- If Left$(tFile$, 1) = Left$(Path$, 1) Then
- Name Path$ + "tTmp.Asc" As tFile$
- Name Path$ + "ClipTmp.Asc" As cFile$
- Else
- 'fix for saving on another drive
- On Error Resume Next
- FileCopy Path$ + "tTmp.Asc", tFile$
- X% = DoEvents()
- FileCopy Path$ + "ClipTmp.Asc", cFile$
- X% = DoEvents()
- Kill Path$ + "tTmp.Asc"
- Kill Path$ + "ClipTmp.Asc"
- End If
- X% = DoEvents()
- End Sub
-
- Sub DeleteRoutine ()
-
- Dim X, Index 'C$, Header$
- '------------------------------------
- 'Exit if Titles listbox is empty
- '------------------------------------
- If MClipForm.Titles.ListCount = 0 Then Exit Sub
- '------------------------------------
- 'Confirm user wants to delete
- '------------------------------------
- X = MsgBox("Are you sure that you want to delete the selected clip?", 68, "Clips")
- If X <> 6 Then Exit Sub
- MClipForm.Titles.Enabled = False
-
- '------------------------------------
- 'Identify record to delete
- '------------------------------------
- Index = MClipForm.Titles.ListIndex
- MClipForm.Titles.RemoveItem Index
- For X = Index To ClipCount% - 2
- Title(X) = Title(X + 1)
- Clip(X) = Clip(X + 1)
- Next
- Clip(X) = ""
- Title(X) = ""
- ClipCount% = ClipCount% - 1
- ReDim Preserve Title(ClipCount%)
- ReDim Preserve Clip(ClipCount%)
- Select Case MClipForm.Titles.ListCount
- Case Is = 0
- ToggleMenu False
- FileDirty% = True
- IgnoreChange% = True
- MClipForm.ClipText = ""
- IgnoreChange% = False
- Case Else
- FileDirty% = True
- MClipForm.Titles.ListIndex = 0
- End Select
- MClipForm.Titles.Enabled = True
- End Sub
-
- Sub GetFiles ()
- Dim C$, X, Y, Look$, D$
- '------------------------------------
- 'Open Titles file
- '------------------------------------
- F = FreeFile
- 'On Error GoTo IDXNotFound
- Open tFile$ For Input As F
- '------------------------------------
- 'Input total records
- '------------------------------------
- Input #F, C$
- ClipCount% = Val(C$)
- If ClipCount% = 0 Then
- ToggleMenu False
- Close F
- IgnoreChange% = True
- MClipForm.ClipText = ""
- IgnoreChange% = False
- Exit Sub
- End If
- '------------------------------------
- 'Redimension Routines() array to hold
- 'titles of all records
- '------------------------------------
- ReDim Title(ClipCount% - 1)
- ReDim Clip(ClipCount% - 1)
- '------------------------------------
- 'Read titles
- '------------------------------------
- For X = 1 To ClipCount%
- Input #F, Title(X - 1)
- MClipForm.Titles.AddItem Title(X - 1)
- Next
- Close F
- '------------------------------------
- 'Get Clip Text for each item
- F = FreeFile
- Open cFile$ For Input As F
- For X = 1 To ClipCount%
- '--------------------------------------------------------
- 'Set Look$ to select item's index tag
- '--------------------------------------------------------
- Look$ = "[" & X & "]"
- '--------------------------------------------------------
- 'Find item's header
- '--------------------------------------------------------
- Do While C$ <> Look$
- Line Input #F, C$
- Loop
- '--------------------------------------------------------
- 'Read Text
- '--------------------------------------------------------
- D$ = ""
- C$ = ""
-
- Line Input #F, C$
- Do While C$ <> CodeEnd$
- D$ = D$ + C$ + CRLF$
- Line Input #F, C$
- Loop
- Clip(X - 1) = D$
- Next X
- '--------------------------------------------------------
- Close F
- '--------------------------------------------------------
- 'Fix Menus and Restore standard pointer
- '--------------------------------------------------------
- ToggleMenu True
- Screen.MousePointer = 1
- '--------------------------------------------------------
-
-
-
- '''
- BackDoor:
- Exit Sub
- '------------------------------------
- 'Error handling routine
- 'Give user chance to create a new
- 'index file if error trying to read old one
- '------------------------------------
- IDXNotFound:
- Y = MsgBox(tFile$ & " Not Found. Create new library?", 20, "VB Code Librarian")
- If Y <> 6 Then End
- ClipCount% = 0
- Resume BackDoor
- End Sub
-
- Sub LibSave ()
- Screen.MousePointer = 11
- Dim Index, Header$, C$
- '------------------------------------
- 'Create tTmp.Asc so that CleanUpFiles doesn't clobber index
- '------------------------------------
- On Error Resume Next
- 'MsgBox Path
- Name cFile$ As Path$ + "tTmp.Asc"
- On Error GoTo 0
- 'Save Title of each item
- F = FreeFile
- Open Path$ + "tTmp.Asc" For Output Access Write As #F
- C$ = Trim(Str$(ClipCount%))
- Print #F, C$
- For RecordNum = 1 To ClipCount%
- Print #F, Title(RecordNum - 1)
- Next
- 'Print #F, Titles(0)
- Close F
- '------------------------------------
- 'Save Text for each item
- '------------------------------------
- F = FreeFile
- Open Path$ + "ClipTmp.Asc" For Output Access Write As #F Len = 4096
- J = FreeFile
- 'Open cFile$ For Input As #J
- For RecordNum = 1 To ClipCount%
- Header$ = "[" & RecordNum & "]"
- Print #F, Header$
- 'Print #F, CodeStart$
- Print #F, Clip(RecordNum - 1)
- Print #F, CodeEnd$
- Next RecordNum
- 'Close J
- Close F
- '------------------------------------
- 'Now clean up files
- '------------------------------------
- CleanUpFiles
- FileDirty% = False
- Screen.MousePointer = 1
- End Sub
-
-