views:

101

answers:

2

Hi, I am trying to attach an html file file to email using Visual Basic 6.0. when the cursor is comes on Open strFile For Binary Access Read As #hFile line it gives error "Error encoding file - Bad file name or number". Please all your help and support would be highly appreciated.

Dim handleFile               As Integer
Dim strValue              As String
Dim lEventCtr           As Long
handleFile = FreeFile
Open strFile For Binary Access Read As #handleFile
Do While Not EOF(hFile)
    ' read & Base 64 encode a line of characters
    strValue = Input(57, #handleFile)
    SendCommand EncodeBase64String(strValue) & vbCrLf

    ' DoEvents (occasionally)
    lEventCtr = lEventCtr + 1
    If lEventCtr Mod 50 = 0 Then DoEvents
Loop
Close #handleFile
Exit Sub
File_Error:
Close #handleFile
m_ErrorDesc = "Error encoding file - " & Err.Description
Err.Raise Err.Number, Err.Source, m_ErrorDesc
End Sub
+1  A: 

Well, it's failing to open the file for reading. Check you have the file path correct, it definitely exists, you have the permissions to read it, no other application has it open and locked against reading...

MarkJ
+2  A: 

This is why you should always use OPTION EXPLICIT. You should check EOF(handleFile) instead of EOF(hFile).

Kaniu
+1 because you're right but I don't think this is causing the error Shax was asking about
MarkJ