Category : Windows 3.X Files
Archive   : CLIPS.ZIP
Filename : MC_FILE.BAS

 
Output of file : MC_FILE.BAS contained in archive : CLIPS.ZIP

DefInt A-Z
Option Explicit
Global Path$ 'application path
Const ClipEnd$ = "[Stop]" 'end of Clip marker for cFile$
Dim F As Integer 'file handle
Dim J As Integer 'file handle
Dim RecordNum As Integer 'identifies current record
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Common Dialog constants
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Global Const OFN_HIDEREADONLY = &H4&
Global Const OFN_OVERWRITEPROMPT = &H2&
Global Const OFN_EXTENTIONDIFFERENT = &H400&
Global Const OFN_FILEMUSTEXIST = &H1000&
Global Const CancelButton = 32755

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 temp files and dest file on same drive
' just rename temp to dest
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
If Left$(tFile$, 1) = Left$(Path$, 1) Then
Name Path$ + "tTmp.Asc" As tFile$
Name Path$ + "ClipTmp.Asc" As cFile$
Else
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' otherwise copy temp files to dest
' then delete temp files
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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

Function Exists% (F$)
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' returns 0 if file not found, or if error in file spec,
' otherwise returns -1
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
On Error Resume Next
Exists% = True
If Len(Dir$(F$)) = 0 Then Exists% = False
On Error GoTo 0
End Function

Sub GetFiles ()
Dim C$, X, Y, Look$, D$
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Open Titles file
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
On Error GoTo IDXNotFound
F = FreeFile
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 Title and Clip arrays to hold
' all clips
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ReDim Title(ClipCount% - 1)
ReDim Clip(ClipCount% - 1)
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Read clip 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$ <> ClipEnd$
D$ = D$ + C$ + CRLF$
Line Input #F, C$
Loop
Clip(X - 1) = D$
Next X
Close F
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Fix Menus and Restore standard pointer
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
BackDoor:
ToggleMenu True
MClipForm.Caption = "Clips -- " + tFile$
Screen.MousePointer = 1

Exit Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Error handling routine
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
IDXNotFound:
MsgBox "Error loading " + tFile$ + ". File truncated."
Close #F
ClipCount% = X%
Dim Z%
Resume BackDoor
End Sub

Sub LoadFile (tFile$)
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' check for existence of MCF and CLP files before proceeding
' exit if either can't be found
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
cFile$ = Left$(tFile$, InStr(tFile$, ".")) + "CLP"
If Not Exists(tFile$) Or Not Exists(cFile$) Then Exit Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' disable titles list (to speed update process)
' set hourglass cursor
' clear list box
' call getfiles routine
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MClipForm.Titles.Enabled = False
Screen.MousePointer = 11
MClipForm.Titles.Clear
GetFiles
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' re-enable list box
' select first item
' reset cursor and FileDirty% variable
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MClipForm.Titles.Enabled = True
If MClipForm.Titles.ListCount Then MClipForm.Titles.ListIndex = 0
Screen.MousePointer = 1
FileDirty% = False
End Sub

Sub SaveClipsFile ()
Screen.MousePointer = 11
Dim Index, Header$, C$
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Create tTmp.Asc so that CleanUpFiles doesn't clobber index
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
On Error Resume Next
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
Close F
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Save Text for each item
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
F = FreeFile
Open Path$ + "ClipTmp.Asc" For Output Access Write As #F Len = 4096
For RecordNum = 1 To ClipCount%
Header$ = "[" & RecordNum & "]"
Print #F, Header$
Print #F, Clip(RecordNum - 1)
Print #F, ClipEnd$
Next RecordNum
Close F
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Now clean up files
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
CleanUpFiles
FileDirty% = False
Screen.MousePointer = 1
End Sub

Sub SaveWithNewName ()
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' set Common Dialog flags
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MClipForm.CMDialog1.Flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT
MClipForm.CMDialog1.DefaultExt = "MCF"
MClipForm.CMDialog1.Filter = "Clips files|*.MCF"
On Error Resume Next
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' call Save dialog
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MClipForm.CMDialog1.Action = 2
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' exit if user pressed cancel button
' otherwise, force an MCF extension
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
If Err = CancelButton Then Exit Sub
If MClipForm.CMDialog1.Flags And OFN_EXTENTIONDIFFERENT Then
MsgBox "File must have an MCF extension!"
Exit Sub
End If
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' set file name and path variables
' call SaveClipsFile routine to save data
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
tFile$ = MClipForm.CMDialog1.Filename
If tFile$ = "" Then Exit Sub
cFile$ = Left$(tFile$, InStr(tFile$, ".")) + "CLP"
Dim X
For X = Len(tFile$) To 1 Step -1
If Mid$(tFile$, X) = "\" Then
Path$ = Left$(tFile$, X)
Exit For
End If
Next
SaveClipsFile
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' update caption to display file name
' * * * * * * * * * * * * * * * * * * * * * * * * * * * *
MClipForm.Caption = "Clips -- " + tFile$
End Sub