Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Error 'Expected End'

Status
Not open for further replies.

Petrolhead

Technical User
Mar 13, 2009
27
0
0
Hi There,

When my contact page runs this script I get the following error:

Error Type:
Sun ONE ASP VBScript compilation (0x800A03F6)
Expected 'End'
/thomas-irvine.com/scripts/contact.asp, line 53, column 51

I think I have closed all the ifs unless the elseifs need closing too.

Can anyone help?

Code:
<%

' declare variables
Dim EmailTo
Dim Subject
Dim Name
Dim Subject
Dim EMailAddress
Dim Message

' get posted data into variables
EmailTo = "tirvine24@gmail.com"
Subject = Trim(Request.Form("Subject")) 
Name = Trim(Request.Form("Name"))  
EMailAddress = Trim(Request.Form("Email")) 
Message = Trim(Request.Form("Message")) 

' validation
Dim validationOK

If  (Trim(Name)="")  Then 
validationOK=false
ElseIf (Trim(Subject)="") Then
validationOK=false
ElseIf (Trim(Email)="") Then
validationOK=false
ElseIf (Trim(Message)="") Then
validationOK=false
Else validaionOK=true
EndIf
If (validationOK=false) Then Response.Redirect("./error.html")
EndIf


' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "Subject: " & Subject & VbCrLf
Body = Body & "E-MailAddress: " & E-MailAddress & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

' send email 
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail") 
mail.To = EmailTo
mail.Subject = Subject
mail.Body = Body
mail.Send 

' redirect to success page 
Response.Redirect("./contact-info-thank-you.htm")
%>
 
I replaced the endif with end if and I'm now getting this error:

Error Type:
Sun ONE ASP VBScript compilation (0x800A0401)
Syntax error, unexpected "Else ", expecting end of statement
/thomas-irvine.com/scripts/contact.asp, line 32, column 1

I've moved the 2nd end if to the end of the script and added an else where the 2nd end if was but i'm still getting this error
 
got it I was missing a carraige return for the syntax
 
got it I was missing a carraige return for the syntax

FYI, if you are running a single command from a condition, it can be written in one line without an "end if"

Code:
' some code here
if myVar = myValue then
   response.write myVar
end if
' more code here

is the same as

Code:
' some code here
if myVar = myValue then response.write myVar
' more code here

If you have multiple things to do within your condition, then it needs to be split up into a proper block.



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top