home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap05 / fileclas.cls < prev    next >
Encoding:
Text File  |  1995-07-12  |  23.7 KB  |  824 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "FileClass"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = False
  8. Option Explicit
  9. #If Win32 Then
  10.     Private Declare Function GetWindowsDirectory Lib "Kernel32" _
  11.         Alias "GetWindowsDirectoryA" _
  12.         (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  13. #Else
  14.     Private Declare Function GetWindowsDirectory Lib "Kernel" _
  15.         (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  16. #End If
  17.  
  18. 'Mode constants
  19. Private Const MODE_APPEND = 0
  20. Private Const MODE_BINARY = 1
  21. Private Const MODE_INPUT = 2
  22. Private Const MODE_OUTPUT = 3
  23. Private Const MODE_INIFILE = 4
  24.  
  25. 'Access constants
  26. Private Const ACCESS_READ = 0
  27. Private Const ACCESS_WRITE = 1
  28. Private Const ACCESS_READWRITE = 2
  29.  
  30.  
  31. 'Internal Property Variables
  32. Private FilePath As String
  33. Private FileTitle As String
  34. Private FileName As String
  35. Private FileMode As Integer
  36. Private FileAccess As Integer
  37. Private FileNumber As Integer
  38. Private LastError As Integer
  39.  
  40. 'Flag variables used only privately
  41. Private AmOpen As Boolean
  42. Private AmDeleted As Boolean
  43.  
  44. 'Constants for trappable file I/O errors
  45. Private Const ErrOutOfMemory = 7
  46. Private Const ErrBadFileNameOrNumber = 52
  47. Private Const ErrFileNotFound = 53
  48. Private Const ErrFileAlreadyOpen = 55
  49. Private Const ErrDeviceIO = 57
  50. Private Const ErrFileAlreadyExists = 58
  51. Private Const ErrDiskFull = 61
  52. Private Const ErrBadFileName = 64
  53. Private Const ErrTooManyFiles = 67
  54. Private Const ErrPermissionDenied = 68
  55. Private Const ErrDiskNotReady = 71
  56. Private Const ErrCantRename = 74
  57. Private Const ErrPathFileAccessError = 75
  58. Private Const ErrPathNotFound = 76
  59.  
  60. '*****************************************************
  61. '
  62. '   Property Procedure
  63. '      Path, Name, Mode, Access,
  64. '      Length, DateTime,
  65. '
  66. '
  67. '*****************************************************
  68.  
  69. Public Property Get Path() As String
  70.     
  71.     If AmDeleted Then
  72.         DeletedMsg
  73.         Exit Property
  74.     End If
  75.     Path = FilePath
  76.  
  77. End Property
  78.  
  79. '========================================================
  80.  
  81. Public Property Let Name(newName As String)
  82.         
  83.     If Not FileExists(FileName) Then
  84.         Dim msg, style, answer
  85.         msg = "The file, """ & newName & """ does not exist.  "
  86.         msg = msg & "Create it?"
  87.         style = vbQuestion Or vbYesNo
  88.         answer = MsgBox(msg, style, App.Title)
  89.         If answer = vbYes Then
  90.             FileCreate newName
  91.         Else
  92.             Exit Property
  93.         End If
  94.     Else
  95.         ProcessPathTitleAndName newName 'Checks for Drive, Directory, etc.
  96.     End If
  97.  
  98. End Property
  99.  
  100. '==========================================================
  101.  
  102. Public Property Get Name() As String
  103.  
  104.     If AmDeleted Then
  105.         DeletedMsg
  106.         Exit Property
  107.     End If
  108.     Name = FileName
  109.  
  110. End Property
  111.  
  112. '==========================================================
  113.  
  114. Public Property Get Title() As String
  115.  
  116.     If AmDeleted Then
  117.         DeletedMsg
  118.         Exit Property
  119.     End If
  120.     Title = FileTitle
  121.  
  122. End Property
  123.  
  124. '===========================================================
  125.  
  126. Public Property Let Mode(NewMode As Integer)
  127.  
  128.     If AmDeleted Then
  129.         DeletedMsg
  130.         Exit Property
  131.     End If
  132.     If NewMode <> FileMode Then
  133.         FileMode = NewMode
  134.         If AmOpen Then
  135.             Close #FileNumber
  136.             FileOpen
  137.         End If
  138.     End If
  139.  
  140. End Property
  141.  
  142. '============================================================
  143.  
  144. Public Property Get Mode() As Integer
  145.     
  146.     If AmDeleted Then
  147.         DeletedMsg
  148.         Exit Property
  149.     End If
  150.     Mode = FileMode
  151.  
  152. End Property
  153.  
  154. '==============================================================
  155.  
  156. Public Property Let Access(NewAccess As Integer)
  157.     
  158.     If AmDeleted Then
  159.         DeletedMsg
  160.         Exit Property
  161.     End If
  162.     If NewAccess <> FileAccess Then
  163.         FileAccess = NewAccess
  164.         If AmOpen Then
  165.             Close #FileNumber
  166.             FileOpen
  167.         End If
  168.     End If
  169.  
  170. End Property
  171.  
  172. '===============================================================
  173.  
  174. Public Property Get Access() As Integer
  175.     
  176.     If AmDeleted Then
  177.         DeletedMsg
  178.         Exit Property
  179.     End If
  180.     Access = FileAccess
  181.  
  182. End Property
  183.  
  184. '================================================================
  185.  
  186. Public Property Get MyError() As Integer
  187.     MyError = LastError
  188. End Property
  189. '================================================================
  190.  
  191. Public Property Get Length() As Long
  192.     
  193.     If AmDeleted Then
  194.         DeletedMsg
  195.         Exit Property
  196.     End If
  197.     Dim FileNum As Integer
  198.     
  199.     If Assert(FileName <> "", _
  200.             "FileObject.Length:  FileName not initialized!") Then
  201.         FileNum = FreeFile
  202.         Open FileName For Binary Access Read As #FileNum
  203.         Length = LOF(FileNum)
  204.         Close FileNum
  205.     End If
  206.     
  207. End Property
  208.  
  209. '===============================================================
  210.  
  211. Public Property Get DateTime() As Variant
  212.     
  213.     If AmDeleted Then
  214.         DeletedMsg
  215.         Exit Property
  216.     End If
  217.     If Not Assert(FileName <> "", _
  218.             "FileObject.FileOpen:  FileName not initialized!") Then
  219.         Exit Property
  220.     End If
  221.     If Assert(FileExists(FileName), _
  222.             "FileObject.DateTime:  FileName not initialized!") Then
  223.         DateTime = FileDateTime(FileName)
  224.     End If
  225.  
  226. End Property
  227.  
  228. '**********************************************************
  229. '
  230. '    Methods
  231. '
  232. '      FileOpen, FileClose, FileMove, FileRename, FileDelete
  233. '
  234. '**********************************************************
  235.  
  236. Public Function FileOpen() As Integer
  237.  
  238.     If AmDeleted Then
  239.         DeletedMsg
  240.         Exit Function
  241.     End If
  242.     
  243.     If Not Assert(FileName <> "", _
  244.             "FileObject.FileOpen:  FileName not initialized!") Then
  245.         Exit Function
  246.     End If
  247.  
  248.     If AmOpen Then Close #FileNumber
  249.     Dim dummy As Variant
  250.     FileNumber = FreeFile
  251.     Select Case FileMode
  252.         Case MODE_APPEND
  253.             Select Case FileAccess
  254.                 Case ACCESS_READ
  255.                     dummy = Assert(False, _
  256.                         "FileObject.FileOpen:  " & _
  257.                         "ReadOnly Access specified for Append action!")
  258.                     AmOpen = False
  259.                 Case ACCESS_WRITE
  260.                     On Error GoTo FileOpenError
  261.                         Open FileName For Append Access Write As #FileNumber
  262.                         AmOpen = True
  263.                         FileOpen = FileNumber
  264.                     On Error GoTo 0
  265.                     Exit Function
  266.                 Case ACCESS_READWRITE
  267.                     dummy = Assert(False, _
  268.                         "FileObject.FileOpen:  " & _
  269.                         "ReadWrite Access specified for Append action!")
  270.                     AmOpen = False
  271.                 Case Else
  272.             End Select
  273.         Case MODE_BINARY
  274.             Select Case FileAccess
  275.                  Case ACCESS_READ
  276.                     On Error GoTo FileOpenError
  277.                     Open FileName For Binary Access Write As #FileNumber
  278.                     AmOpen = True
  279.                     FileOpen = FileNumber
  280.                     On Error GoTo 0
  281.                     Exit Function
  282.                  Case ACCESS_WRITE
  283.                     On Error GoTo FileOpenError
  284.                     Open FileName For Binary Access Write As #FileNumber
  285.                     AmOpen = True
  286.                     FileOpen = FileNumber
  287.                     On Error GoTo 0
  288.                     Exit Function
  289.                 Case ACCESS_READWRITE
  290.                     On Error GoTo FileOpenError
  291.                     Open FileName For Binary Access Read Write As #FileNumber
  292.                     AmOpen = True
  293.                     FileOpen = FileNumber
  294.                     On Error GoTo 0
  295.                     Exit Function
  296.                 Case Else
  297.             End Select
  298.         Case MODE_INPUT
  299.             Select Case FileAccess
  300.                  Case ACCESS_READ
  301.                     On Error GoTo FileOpenError
  302.                     Open FileName For Input Access Read As #FileNumber
  303.                     AmOpen = True
  304.                     FileOpen = FileNumber
  305.                     On Error GoTo 0
  306.                     Exit Function
  307.                  Case ACCESS_WRITE
  308.                     dummy = Assert(False, _
  309.                         "FileObject.FileOpen:  " & _
  310.                         "Attempting Access Write with Input mode!")
  311.                     Exit Function
  312.                 Case ACCESS_READWRITE
  313.                     dummy = Assert(False, _
  314.                         "FileObject.FileOpen:  " & _
  315.                         "Attempting Access Read Write with Input mode!")
  316.                     Exit Function
  317.                 Case Else
  318.             End Select
  319.         Case MODE_OUTPUT
  320.             Select Case FileAccess
  321.                  Case ACCESS_READ
  322.                     dummy = Assert(False, _
  323.                         "FileObject.FileOpen: " & _
  324.                         "Attempting Access Read with Output mode!")
  325.                     Exit Function
  326.                  Case ACCESS_WRITE
  327.                     On Error GoTo FileOpenError
  328.                     Open FileName For Output Access Write As #FileNumber
  329.                     AmOpen = True
  330.                     FileOpen = FileNumber
  331.                     On Error GoTo 0
  332.                     Exit Function
  333.                 Case ACCESS_READWRITE
  334.                     dummy = Assert(False, _
  335.                         "FileObject.FileOpen:  " & _
  336.                         "Attempting Access Read Write with Output mode!")
  337.                     Exit Function
  338.                 Case Else
  339.             End Select
  340.         Case Else
  341.             dummy = Assert(False, _
  342.                 "FileObject.FileOpen:  " & _
  343.                 "Incorrect File Mode parameter set!")
  344.             Exit Function
  345.     End Select
  346. FileOpenError:
  347.     Dim action As Integer, ErrNumber As Integer
  348.     action = Errors()
  349.     Select Case action
  350.         Case 0
  351.             Resume
  352.         Case 1
  353.             Resume Next
  354.         Case 2, 3
  355.             Exit Function
  356.         Case Else
  357.             ErrNumber = Err.Number
  358.             Err.Raise ErrNumber
  359.             Err.Clear
  360.     End Select
  361.  
  362. End Function
  363.  
  364. '=========================================================
  365.  
  366. Public Sub FileClose()
  367.     
  368.     If AmDeleted Then
  369.         DeletedMsg
  370.         Exit Sub
  371.     End If
  372.      
  373.     If Not Assert(FileName <> "", _
  374.         "FileObject.FileOpen:  FileName not initialized!") Then
  375.         Exit Sub
  376.     End If
  377.  
  378.     If AmOpen Then
  379.         Close #FileNumber
  380.         FileNumber = 0
  381.         AmOpen = False
  382.     End If
  383.  
  384. End Sub
  385.  
  386. '========================================================
  387.  
  388. Public Sub FileMove(NewPath As String)
  389.     
  390.     If Not Assert(FileName <> "", _
  391.         "FileObject.FileMove:  FileName not initialized!") Then
  392.         Exit Sub
  393.     End If
  394.   
  395.     'Check Drive Spec
  396.     Dim newName As String, SourceNum As Integer, TargetNum As Integer
  397.     If VBA.Right$(NewPath, 1) = "\" Then   'Get the path in shape
  398.         newName = NewPath & FileTitle
  399.     Else
  400.         newName = NewPath & "\" & FileTitle
  401.     End If
  402.     If InStr(NewPath, ":") Then   'There is a drive spec included
  403.         If VBA.Left$(newName, 1) <> VBA.Left$(FileName, 1) Then
  404.             'Different drive, Name command won't work
  405.             DoFileCopy FileName, newName
  406.             Kill FileName
  407.             ProcessPathTitleAndName newName
  408.         End If
  409.     Else
  410.         On Error GoTo FileMoveError
  411.         Name FileName As newName
  412.         On Error GoTo 0
  413.         ProcessPathTitleAndName newName
  414.     End If
  415.     Exit Sub
  416.  
  417. FileMoveError:
  418.     Dim action As Integer, ErrNumber As Integer
  419.     action = Errors()
  420.     Select Case action
  421.         Case 0
  422.             Resume
  423.         Case 1
  424.             Resume Next
  425.         Case 2, 3
  426.             Exit Sub
  427.         Case Else
  428.             ErrNumber = Err.Number
  429.             Err.Raise ErrNumber
  430.             Err.Clear
  431.     End Select
  432.  
  433. End Sub
  434.  
  435. '==============================================================
  436.  
  437. Public Sub FileRename(newName As String)
  438.  
  439.     If Not Assert(FileName <> "", _
  440.         "FileObject.FileRename:  FileName not initialized!") Then
  441.         Exit Sub
  442.     End If
  443.  
  444.     On Error GoTo FileRenameError
  445.     If InStr(newName, ":") Then  'there is a drive spec
  446.         If VBA.Left$(newName, 1) <> VBA.Left$(FileName, 1) Then
  447.             DoFileCopy FileName, newName
  448.             Kill FileName
  449.         Else
  450.             Name FileName As newName
  451.         End If
  452.     Else
  453.         Name FileName As newName
  454.     End If
  455.     On Error GoTo 0
  456.     ProcessPathTitleAndName newName
  457.         
  458. FileRenameError:
  459.     Dim action As Integer, ErrNumber As Integer
  460.     action = Errors()
  461.     Select Case action
  462.         Case 0
  463.             Resume
  464.         Case 1
  465.             Resume Next
  466.         Case 2, 3
  467.             Exit Sub
  468.         Case Else
  469.             ErrNumber = Err.Number
  470.             Err.Raise ErrNumber
  471.             Err.Clear
  472.     End Select
  473.  
  474. End Sub
  475.  
  476. '===============================================================
  477.  
  478. Public Sub FileDelete()
  479.     
  480.     If Not Assert(FileName <> "", _
  481.         "FileObject.FileOpen:  FileName not initialized!") Then
  482.         Exit Sub
  483.     End If
  484.     
  485.     If AmOpen Then Close #FileNumber
  486.     If AmDeleted Then
  487.         DeletedMsg
  488.         Exit Sub
  489.     End If
  490.     
  491.     Kill FileName
  492.     
  493.     AmDeleted = True
  494.     FileNumber = 0
  495.     
  496.  
  497. End Sub
  498.  
  499. '===================================================
  500.  
  501. Public Sub FileCreate(newName As String)
  502.  
  503.     Dim FileNum As Integer
  504.     Dim choice As Integer
  505.     
  506.     FileNum = FreeFile
  507.     Open newName For Output As #FileNum
  508.     Close FileNum
  509.  
  510.     ProcessPathTitleAndName newName
  511.     AmDeleted = False
  512.     
  513. End Sub
  514.  
  515. '===================================================
  516.  
  517. Public Sub FileCopy(newName As String, Optional RegisterNew As Variant)
  518.     
  519.     If Not Assert(FileName <> "", _
  520.         "FileObject.FileOpen:  FileName not initialized!") Then
  521.         Exit Sub
  522.     End If
  523.  
  524.     DoFileCopy FileName, newName
  525.     
  526.     If Not IsMissing(RegisterNew) And RegisterNew = True Then
  527.         ProcessPathTitleAndName newName
  528.     End If
  529.     
  530. End Sub
  531.  
  532. '=====================================================
  533.  
  534. Private Function Errors() As Integer
  535.  
  536.     Dim MsgType As Integer, msg As String, response As Integer
  537.     Dim NewFileNameNeeded As Boolean
  538.     Dim DoResume As Boolean
  539.     Dim DoResumeNext As Boolean
  540.     'Return Value     Meaning     Return Value     Meaning
  541.     '      0          Resume            2          Filename Error
  542.     '      1          Resume Next       3          Unrecoverable Error
  543.     '                                   4          Unrecognized Error
  544.     MsgType = vbExclamation
  545.     Select Case Err.Number
  546.         Case ErrOutOfMemory '7
  547.             msg = "The operating system reports that there is not "
  548.             msg = msg & "enough memory to complete this operation.  "
  549.             msg = msg & "You can try closing some other applications and then "
  550.             msg = msg & "click Retry to try again or you can click Cancel to exit."
  551.             MsgType = vbExclamation + vbRetryCancel
  552.             DoResume = True
  553.             'Resume or Exit
  554.         Case ErrBadFileNameOrNumber, ErrBadFileName
  555.             msg = "That file name is illegal!"
  556.             NewFileNameNeeded = True
  557.             DoResume = True
  558.             'Resume
  559.         Case ErrFileNotFound
  560.             msg = "That file does not exist.  Create it?"
  561.             MsgType = vbExclamation + vbOKCancel
  562.             DoResumeNext = True
  563.             'Resume Next
  564.         Case ErrFileAlreadyOpen
  565.             msg = "That file is already in use."
  566.             MsgType = vbExclamation + vbRetryCancel
  567.             NewFileNameNeeded = True
  568.             'New Name
  569.         Case ErrDeviceIO
  570.             msg = "Internal disk error."
  571.             MsgType = vbExclamation + vbRetryCancel
  572.             DoResume = True
  573.             'Resume
  574.         Case ErrFileAlreadyExists
  575.             msg = "A file with that name already exists.  "
  576.             msg = msg & "Replace it?"
  577.             MsgType = vbExclamation + vbOKCancel
  578.             NewFileNameNeeded = True
  579.             'New Name
  580.         Case ErrDiskFull
  581.             msg = "This disk is full.  Continue?"
  582.             MsgType = vbExclamation + vbOKCancel
  583.             DoResume = True
  584.             'Resume
  585.         Case ErrTooManyFiles
  586.             msg = "The operating system reports that too "
  587.             msg = msg & "many files are currently open.  You "
  588.             msg = msg & "can try closing some other applications "
  589.             msg = msg & "and then try again."
  590.             MsgType = vbExclamation + vbRetryCancel
  591.             DoResume = True
  592.             'Resume
  593.         Case ErrPermissionDenied
  594.             msg = "You have tried to write to a file that is in "
  595.             msg = msg & "use or is designated as read-only."
  596.             NewFileNameNeeded = True
  597.             'New Name
  598.         Case ErrDiskNotReady
  599.             msg = "Insert a disk in the drive and close the door"
  600.             MsgType = vbExclamation + vbOKCancel
  601.             DoResume = True
  602.             'Resume
  603.         Case ErrPathFileAccessError, ErrPathNotFound
  604.             msg = "The operating system cannot locate this file on "
  605.             msg = msg & "this path.  Check to make sure that the file "
  606.             msg = msg & "name and path have been entered correctly "
  607.             msg = msg & "and then try again."
  608.             NewFileNameNeeded = True
  609.         Case Else
  610.             Errors = 4
  611.             Exit Function
  612.     End Select
  613.     response = MsgBox(msg, MsgType, "File Error")
  614.     Select Case response
  615.         Case vbRetry, vbOK
  616.             If NewFileNameNeeded Then
  617.                 LastError = FOBJ_ERROR_FILENAME
  618.             ElseIf DoResume Then
  619.                 LastError = FOBJ_ERROR_RESUME
  620.             ElseIf DoResumeNext Then
  621.                 LastError = FOBJ_ERROR_RESUMENEXT
  622.             Else
  623.                 LastError = FOBJ_ERROR_UNRECOVERABLE
  624.             End If
  625.         Case Else
  626.             LastError = FOBJ_ERROR_UNRECOGNIZABLE
  627.     End Select
  628.     Errors = LastError
  629.  
  630. End Function
  631.  
  632. '===========================================================
  633.  
  634. Private Function FileExists(theName As String) As Boolean
  635.     FileExists = (Dir(theName) <> "")
  636. End Function
  637.  
  638. '**********************************************************
  639. '
  640. '    Private Utility Functions
  641. '
  642. '
  643. '
  644. '**********************************************************
  645.  
  646. Private Sub ProcessPathTitleAndName(newName As String)
  647.  
  648.    Dim BackSlash As Integer
  649.    If InStr(newName, "\") Then
  650.         BackSlash = RInstr(0, newName, "\")
  651.         FilePath = VBA.Left$(newName, BackSlash - 1)
  652.         FileTitle = Mid$(newName, BackSlash + 1)
  653.     ElseIf InStr(newName, ":") Then
  654.         Dim CurDrive As String
  655.         Dim TargetDrive As String
  656.         TargetDrive = VBA.Left$(newName, 1)
  657.         CurDrive = CurDir$
  658.         If VBA.Left$(CurDrive, 1) <> TargetDrive Then
  659.             ChDrive TargetDrive
  660.             FilePath = CurDir$
  661.             ChDrive CurDrive
  662.         Else
  663.             FilePath = CurDir$
  664.         End If
  665.         FileTitle = Mid$(newName, InStr(newName, ":") + 1)
  666.     Else
  667.         FilePath = CurDir$
  668.         FileTitle = newName
  669.     End If
  670.     FileName = FilePath & "\" & FileTitle
  671.  
  672. End Sub
  673.  
  674. '=======================================================
  675.  
  676. Private Sub DoFileCopy(Source As String, Target As String, _
  677.         Optional Overwrite As Variant)
  678.         
  679.     Dim ErrorMsg As String, SourceNum As Integer, TargetNum As Integer
  680.     Dim buffer As String, TheLength As Long
  681.     
  682.     ErrorMsg = "FileObject.DoFileCopy: Attempting "
  683.     ErrorMsg = ErrorMsg & "copy/move operation on non-existent file!"
  684.     If Assert(FileExists(Source), ErrorMsg) Then
  685.         SourceNum = FreeFile: TargetNum = FreeFile
  686.         On Error GoTo DoFileCopyError
  687.         Open Source For Binary Access Read As SourceNum
  688.         On Error GoTo 0
  689.         If FileExists(Target) Then
  690.             If IsMissing(Overwrite) Or Overwrite = False Then
  691.                 'Get confirmation
  692.                 Dim msg As String, style As Integer, answer As Integer
  693.                 msg = "The file, """ & Source & """ already exists.  "
  694.                 msg = msg & "This action will overwrite it.  Continue?"
  695.                 style = vbQuestion & vbYesNo
  696.                 answer = MsgBox(msg, style, App.Title)
  697.                 If answer = vbNo Then
  698.                     Exit Sub
  699.                 End If
  700.             End If
  701.         End If
  702.         TheLength = LOF(SourceNum)
  703.         On Error GoTo DoFileCopyError
  704.             Open Source For Binary Access Read As SourceNum
  705.             Open Target For Binary Access Write As TargetNum
  706.         On Error GoTo 0
  707.         If TheLength < 60000 Then
  708.             'Take the file in bits
  709.             Do Until TheLength < 60000
  710.                 buffer = String$(0, 60000)
  711.                 Get SourceNum, , buffer
  712.                 Put TargetNum, , buffer
  713.                 TheLength = TheLength - Len(buffer)
  714.             Loop
  715.             buffer = String$(0, TheLength)
  716.             Get SourceNum, , buffer
  717.             Put TargetNum, , buffer
  718.         Else
  719.             buffer = String$(0, TheLength)
  720.             Get #SourceNum, , buffer
  721.             Put TargetNum, , buffer
  722.         End If
  723.         Close #SourceNum
  724.         Close #TargetNum
  725.     End If
  726.     Exit Sub
  727.     
  728. DoFileCopyError:
  729.     Dim action As Integer, ErrNumber As Integer
  730.     action = Errors()
  731.     Select Case action
  732.         Case 0
  733.             Resume
  734.         Case 1
  735.             Resume Next
  736.         Case 2, 3
  737.             Exit Sub
  738.         Case Else
  739.             ErrNumber = Err.Number
  740.             Err.Raise ErrNumber
  741.             Err.Clear
  742.     End Select
  743.     
  744. End Sub
  745.  
  746. '============================================================
  747.  
  748. Sub DeletedMsg()
  749.     
  750.     Dim msg, style
  751.     msg = "You have deleted the file """ & FileName & "."""
  752.     msg = msg & "  You must reinitialize the FileObject with a "
  753.     msg = msg & "new valid file name before proceeding!"
  754.     style = vbCritical + vbOKOnly
  755.     MsgBox msg, style, App.Title
  756.     
  757. End Sub
  758.  
  759. '========================================================
  760.  
  761. Private Function OverwriteWarning(FileName As String) As Integer
  762.  
  763.     Dim msg As String, style As Integer
  764.     
  765.     msg = "The file, " & FileName & ", already exists in the current "
  766.     msg = msg & "directory.  Overwrite it?"
  767.     style = vbQuestion Or vbYesNo
  768.     OverwriteWarning = MsgBox(msg, style, App.Title)
  769.  
  770. End Function
  771.  
  772. '=========================================================
  773.  
  774. Private Function RInstr(Start As Integer, Source As String, _
  775.     Goal As String) As Integer
  776.     
  777.     Dim Index As Integer, N As Integer
  778.     
  779.     If Start <> 0 Then Index = Start Else Index = Len(Source)
  780.     For N = Index To 1 Step -1
  781.         If Mid$(Source, N, 1) = Goal Then
  782.             RInstr = N
  783.             Exit Function
  784.         End If
  785.     Next
  786.     RInstr = 0
  787.  
  788. End Function
  789.  
  790. '**********************************************************
  791. '
  792. '    Class Initialization and Destruction
  793. '
  794. '
  795. '
  796. '**********************************************************
  797.  
  798. Private Sub Class_Initialize()
  799.  
  800.     Dim nResult As Integer
  801.     Dim buffer As String
  802.     
  803.     'Initializes the object to an ubiquitous file
  804.     'This works in tandem with the inifile object
  805.     'by setting things to point to WIN.INI
  806.     FileTitle = "WIN.INI"
  807.     buffer = String$(200, 0)
  808.     nResult = GetWindowsDirectory(buffer, Len(buffer))
  809.     FilePath = VBA.Left$(buffer, nResult)
  810.     FileName = FilePath & "\" & FileTitle
  811.     FileMode = MODE_BINARY
  812.     FileAccess = ACCESS_READWRITE
  813.     
  814. End Sub
  815.  
  816.  
  817.  
  818.  
  819. Private Sub Class_Terminate()
  820.     If FileNumber <> 0 Then
  821.         Close #FileNumber
  822.     End If
  823. End Sub
  824.