View Full Version : Very basic VB.net sytax question
david7777
03-11-2003, 02:04 PM
I am currently converting my site from asp to asp.net.
Sheepishly i ask this question:
i used to have:
on error resume next
'....code....
if not err = 0 then
'....code....
end if
It used to work fine, but now, in asp.net, it doesn't...
I get the error:
Operator '=' is not defined for types 'Microsoft.VisualBasic.ErrObject' and 'Integer'.
What do i use? I have tried <> as well, but same error.
allida77
03-11-2003, 03:13 PM
In my .net pages I usually use:
Try
'where code is
Catch ex As Exception
'if there are any problems with the code it is caught here
Finally
'aways do this bit of code
End Try
Depending on what you are "trying" different exceptions will be thrown.Check out msdn for more info.
david7777
03-11-2003, 03:25 PM
Thanx a lot - I knew about exception handling, but for some reason I forgot to use it this time... :o
Roy Sinclair
03-11-2003, 05:09 PM
Using proper error handling in .net is the right way to go but the basic problem you started with is that the err object no longer defaults to the err.number field. Using err.number would have also solved the problem.
Worldcrossings
03-18-2009, 07:10 PM
Ok, sorry I need a little more information, as I have the same problem but don't quite understand how to use the answer here. This is what i normally used:
On Error Resume Next
Mail.Send()
Mail = Nothing
If Err() <> 0 Then
Response.Write("<strong>There has been an error and your message WAS NOT SENT through email. <BR></strong>" & Err.Description)
End If
Would this be correct:
Try
Mail.Send()
Mail = Nothing
Catch ex As Exception
Response.Write("<strong>There has been an error and your message WAS NOT SENT through email. <BR></strong>" & Err.Description)
End Try
What about the if/then statement, is that needed to write the response.write? If so, how... :)
Thanks in advance!
TT
Worldcrossings
03-18-2009, 07:56 PM
Alright, I think I answered my question, the IFTHEN statement is NOT needed in the Catch ex, cause if the mail connection doesn't send, the first warning gets written, but now I have one issue:
Try
Mail.Send()
Mail = Nothing
Catch ex As Exception
Response.Write("<strong>There has been an error and your message WAS NOT SENT through email. <BR></strong>" & Err.Description)
End Try
If ex() > 0 Then
Response.Write("<P>Thank-You <strong>" & strYourName & "</strong>! Your message has been successfully sent.")
Response.Write("<P>The user account will be terminated.")
End If
How do I get the IFTHEN statement to run if there is no issues with the mail being sent?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.