Dim GlobalUserClickedFilename As Integer

Declare Function VnsSimpleSendMail Lib "sendmail.dll" (ByVal pszFileName As String) As Integer

Sub Command1_Click ()
    SimpleSend
End Sub

Sub Command2_Click ()
    End
End Sub

Sub Dir1_Change ()
    File1.Path = Dir1.Path
    Label3.Caption = File1.Path
End Sub

Sub Drive1_Change ()
    Dir1.Path = Drive1.Drive
End Sub

Sub File1_Click ()
    UserClickedFilename = True

    If Right(File1.Path, 1) <> "\" Then
        Text1.Text = File1.Path + "\" + File1.FileName
    Else
        Text1.Text = File1.Path + File1.FileName
    End If
End Sub

Sub File1_DblClick ()
    SimpleSend
End Sub

'----------------------------------------------------------
' Check for the existence of a file by attempting an OPEN.
'----------------------------------------------------------
Function FileExists (Path$) As Integer

    x = FreeFile

    On Error Resume Next
    Open Path$ For Input As x
    If Err = 0 Then
        FileExists = True
    Else
        FileExists = False
    End If
    Close x

End Function

Sub Form_Load ()
    UserClickedFilename = False
End Sub

Sub SimpleSend ()
' DOS defines _MAX_PATH at 260 chars
    Dim NameOfFile As String
    Dim ReturnCode As Integer

' if the user clicked the filename from the file
' listbox, or typed the filename in the textbox,
' then don't pre-pend any filepath info
    If (UserClickedFilename = True) Or (Mid(Text1.Text, 2, 1) = ":") Then
        NameOfFile = Text1.Text
    Else
        NameOfFile = File1.Path + "\" + Text1.Text
    End If
    
    If FileExists(NameOfFile) <> 0 Then
        ReturnCode = VnsSimpleSendMail(NameOfFile)
    Else
        MsgBox NameOfFile, 0 + 32 + 0, "File not found"
        'Text1.Text = "File not found: " + NameOfFile
    End If
End Sub

Sub Text1_DblClick ()
    SimpleSend
End Sub

