.BUF File

gpnhmiller

Registered User.
Local time
Today, 08:51
Joined
Aug 24, 2012
Messages
17
I have a file called CAPTURE.BUF. I am trying to convert it to text. Here is what I ahve done, but I get the message box ever time. Can someone tell me what I am doing wrong?

Public Function copyFile()
Dim SourceFile As String
Dim DestinationFile As String
SourceFile = "C:\PCPICSW\CAPTURE.BUF"
DestinationFile = "C:\INVESTMENT_REPORTS\CAPTURE.TXT"
On Error Resume Next
FileCopy SourceFile, DestinationFile
If Error > 0 Then
MsgBox "Could not copy mls file."
End If
On Error GoTo 0

End Function


Thanks, Greg
 
How about changing the error handling?

First off Error isn't going to be > 0. Err.Number will be.

And I don't like using ResumeNext because it hides things. So if I get a specific error number for something and I know it is okay to ignore it then I use that in my error handler like

If Err.Number <> xxxx Then
 
So you're saying it should be like this:

Public Function copyFile()
Dim SourceFile As String
Dim DestinationFile As String
SourceFile = "C:\PCPICSW\CAPTURE.BUF"
DestinationFile = "C:\INVESTMENT_REPORTS\CAPTURE.TXT"
FileCopy SourceFile, DestinationFile
If Err.Number <> 1000 Then
MsgBox "Could not copy mls file."
End If
On Error GoTo 0

End Function
 
So you're saying it should be like this:

Public Function copyFile()
Dim SourceFile As String
Dim DestinationFile As String
SourceFile = "C:\PCPICSW\CAPTURE.BUF"
DestinationFile = "C:\INVESTMENT_REPORTS\CAPTURE.TXT"
FileCopy SourceFile, DestinationFile
If Err.Number <> 1000 Then
MsgBox "Could not copy mls file."
End If
On Error GoTo 0

End Function
Well, I prefer to use an actual Error Handler:

Code:
Public Function copyFile()
    [B][COLOR=red]On Error GoTo err_handler[/COLOR][/B]
    
    Dim SourceFile As String
    Dim DestinationFile As String
    
    SourceFile = "C:\PCPICSW\CAPTURE.BUF"
    
    DestinationFile = "C:\INVESTMENT_REPORTS\CAPTURE.TXT"
    
    FileCopy SourceFile, DestinationFile
    
[B][COLOR=red]exit_copyFile:
Exit Function[/COLOR][/B]
 
[B][COLOR=red]err_handler:
If Err.Number <> 1000 Then
    MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
    Resume exit_copyFile
    Resume
End If
[/COLOR][/B]End Function
 
What does the second resume do?

That is a good question. I have learned to put that in there so that when I am debugging, if an error is thrown (code goes into break mode) I can move the yellow line where it stopped to that and it will go back to the place the original error occurred. It can be very useful.
 
Cool - I remember seeing that somewhere :)

edit:

So you get an error and it goes to the on error line,
then you get the msgbox,
then it hits the first resume where it goes to the exit sub line.

Is this what happens? If so how does it do what you said?
 
Bob, after changing the code all I get is out of stck space followed by type mismatch errors...
 
Bob, after changing the code all I get is out of stck space followed by type mismatch errors...
And that is good. You're making progress. The On Error Resume Next was obscuring those errors.

So, the question is - can you manually change the file extension to .txt and then it works to open in NotePad or WordPad? Just starting with the basics to see if we can work this out.
 

Users who are viewing this thread

Back
Top Bottom