Hello All
I have question about the way Err object works in VB. It's like this:
I have a procedure called ReplaceData, which open a file thru. a Class
oFso's OpenFile command. Now oFso has a procedure called BackupFile()
that is called if the OpenFile command was called with a ToWrite
parameter. Now if the directory where the BackupFile() operates on has
only Read access, then it should pass the Err to the calling routine
which is OpenFile which should then pass it to ReplaceData.
However it's not doing that and I can't trap it in ReplaceData() since
it's being shown as a runtime error in OpenFile.
Could someone please tell me what I'm missing here.
thanks
Sunit
Public Function ReplaceData(ByVal sNewNode As String, ByVal sNewDrive
As String, ByVal blnReplaceFirstLine As Boolean) As String
oFso.OpenFile ToWrite
oFso.WriteString sTemp
oFso.CloseFile
ReplaceData = "Replaced all data in " & sFileName & "."
Exit Function
ErrorHandler:
Err.Raise Err.Number, MODULE_NAME & ".ReplaceData" &
Err.Description
End Function
'From oFso's Class
Public Sub OpenFile(Optional OpMode As OpenMode = ToRead, _
Optional CreateIfNotExist As Boolean = False)
On Error GoTo ErrorHandler
If OpMode <> ToRead Then
BackupFile 'Backup if file is not Opened for Reading
Set oTxt = oFso.OpenTextFile(sFileName, OpMode,
CreateIfNotExist)
Else
fnum = FreeFile()
Open sFileName For Input As #fnum
isOpen = True
End If
Exit Sub
ErrorHandler:
If isOpen Then Close #fnum
If Err.Number <> 0 Then Err.Raise Err.Number, MODULE_NAME &
".OpenFile", Err.Description 'It stops here instead of passing it to
ReplaceData()
End Sub
Private Sub BackupFile()
Dim sBackupFile, oTrace As New CTracer
On Error GoTo ErrorHandler
sBackupFile = sFileName & ".bk"
oTrace.Enter "Backupfile->" & sBackupFile
oFso.CopyFile sFileName, sBackupFile
ErrorHandler:
If Err.Number <> 0 Then Err.Raise Err.Number, MODULE_NAME &
".Backup", Err.Description
End Sub