Log in

View Full Version : TRY, IF, THEN error ... need help please ...



WCScript
03-19-2009, 04:04 PM
Can someone help me with this please? I have a form on a .NET webserver using aspx pages with the vb code-behind pages. The form collects the entered data and then emails it, that part works fine.

Right after it gets emailed, this code checks to see if the email was sent or not and then updates the landing page accordingly. I used to use just an IF THEN statement, but now that doesn't work in these new .NET pages.

Here's the end of the code that I am having difficulties with:




Try
Mail.Send()
Mail = Nothing

Catch ex As Exception
Response.Write("There has been an error and your message WAS NOT SENT through email." & Err.Description)

Finally
If Mail >= 1 Then
Response.Write("It worked, your form has been submitted by email!!!")
End If

End Try


Specifically, this is the part that's throwing the error:


If Mail >= 1 Then

The error is:
Operator '>' is not defined for type 'IMailSend' and 'Nothing'

is there a better way to write this whole block of code?

Twey
03-19-2009, 04:21 PM
Well, there is a reason for that: your code doesn't make sense. How could it be >= 1? It's either an IMailSend or a Nothing. How do those compare to 1?

WCScript
03-19-2009, 05:33 PM
OK, that makes sense but I'm to stupid to know how to fix it ... :(

Would it be this then:


Try
Mail.Send()
Mail = Nothing

Catch ex As Exception
Response.Write("There has been an error and your message WAS NOT SENT through email." & Err.Description)

Finally
If Mail = IMailSend Then
Response.Write("It worked, your form has been submitted by email!!!")
End If

End Try

Am I close? :)

WCScript
03-19-2009, 05:55 PM
Nevermind, I got the answer. It should be:


Try
Mail.Send()

Response.Write("It worked, your form has been submitted by email!!!")

Catch ex As Exception
Response.Write("There has been an error and your message WAS NOT SENT through email." & Err.Description)

Finally
Mail = Nothing
End Try

I had everything backwards ...