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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

else if statement 3

Status
Not open for further replies.

rochnn

Technical User
Sep 16, 2006
9
US
hello, with great help from Sheco I was able to get the date month and day. Now my problem is I am trying to build and else if statement but I get this error

Microsoft VBScript compilation (0x800A03EA)
Syntax error
/date.asp, line 17
else

here is what my code looks like

Code:
<% 
dim x, y
x = Year(Now())
y = Month(Now())


 If x = "2006" then response.Write("F") 
 else
 if x = "2007" then response.Write("G")
  else
 if x = "2008" then response.Write("H")
  else
 if x = "2008" then response.Write("I")
  else
 if x = "2009" then response.Write("J")
  else
 if x = "2010" then response.Write("K")
and 
 if y = "1" then response.Write("A")
 else
 if y = "2" then response.write("B")
 else
 if y = "3" then response.write("C")
  else
 if y = "4" then response.write("D")
  else
 if y = "5" then response.write("E")
  else
 if y = "6" then response.write("F")
  else
 if y = "7" then response.write("G")
  else
 if y = "8" then response.write("H")
  else
 if y = "9" then response.write("I")
  else
 if y = "10" then response.write("J")
  else
 if y = "11" then response.write("K")
  else
 if y = "12" then response.write("L")
 
 END IF
 
   %>
 
Code:
<%
dim x, y
x = Year(Now())
y = Month(Now())


 If x = "2006" then response.Write("F")
 else
 if x = "2007" then response.Write("G")
  else
 if x = "2008" then response.Write("H")
  else
 if x = "2008" then response.Write("I")
  else
 if x = "2009" then response.Write("J")
  else
 if x = "2010" then response.Write("K")
[b]and ???[/b]
 if y = "1" then response.Write("A")
 else
 if y = "2" then response.write("B")
 else
 if y = "3" then response.write("C")
  else
 if y = "4" then response.write("D")
  else
 if y = "5" then response.write("E")
  else
 if y = "6" then response.write("F")
  else
 if y = "7" then response.write("G")
  else
 if y = "8" then response.write("H")
  else
 if y = "9" then response.write("I")
  else
 if y = "10" then response.write("J")
  else
 if y = "11" then response.write("K")
  else
 if y = "12" then response.write("L")
 
 END IF
 
   %>
 
Why do you have "and" between "else if" statements?
 
Because I wanted to display FJ
F=2006
J=10
do I have to do it in separate statements?
 
Oh sorry, I got it now. You should have "end if" at the end of
condition of X
 
I took the and out and put "end if" (with no quotes) and I got this error

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/date.asp, line 17
else

all I have in Line 17 is "else" (with no quotations)
 
Combine your ElseIf into one word...no space between them.

Also, that And is throwing it off.
Code:
If x = 2006 Then
  Response.write("Year 2006")
ElseIf x = 2007 Then
  Response.write("Year 2007")
ElseIf x = 2008 Then
  Response.write("Year 2008")
End If

If y = 1 Then
  Response.write("Month 1")
ElseIf y = 2 Then
  Response.write("Month 2")
ElseIf y = 3 Then
  Response.write("Month 3")
End If

If (x = 2006) AND (y = 10) Then
  Response.write("Oct 2006")
ElseIf (x = 2006) AND (y = 11) Then
  Response.write("Nov 2006")
Else
  Response.write("Not Oct. or Nov. in 2006")
End If

or...

SELECT CASE(y)
CASE 1
  If x = 2006 Then
    Response.write("Month 1 in 2006")
  Else
    Response.write("Month 1 some other year")
  End If
Case 2
  If x = 2006 Then
    Response.write("Month 2 in 2006")
  Else
    Response.write("Month 2 some other year")
  End IF
Case Else
  If x = 2006 Then
    Response.write("Some month in 2006")
  Else
    Response.write("Some Month in Some Year??")
  End If
End Select

Hope this helps...


-Ovatvvon :-Q
 
Should be like this:

Code:
<%
If x = "2006" then response.Write("F")
 elseif x = "2007" then response.Write("G")
 else
   ......
End If

if y = "1" then response.Write("A")
 elseif y = "2" then response.write("B")
 else
   ....
End If
%>

"elseif" is one word
 
Thank you so vey much Kendel and Ovatvvon I appreciate the help.
 
Do some testing, but I think this should work for you.

Code:
<%
dim x, y
x = Year(Now())
y = Month(Now())
    
    Response.Write(chr(x-1936))
    Response.Write(chr(y+64))
 %>

Basically, we do a little math with the month and year and convert it's ascii value.

This will prevent goofy typo's like this...

[tt][blue]
if x = "[!]2008[/!]" then response.Write("[!]H[/!]")
else
if x = "[!]2008[/!]" then response.Write("[!]I[/!]")
[/blue][/tt]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top