Home > ASP Development > problem with if var > 12 and var2 = x then

problem with if var > 12 and var2 = x then



Hi I am having a problem with a simple ifelse statement, i can feel the answer is staring me in the face but i just cant suss it.

It's an ifelse statement that should increment a var from the current month number to 12(dec) then to 1()jan, another goes from current month no. to 1(jan) then to 12(dec)

What happens however is that it just keeps incrementing or decrementing and breaks the code when Tmonth = < 1 or > 12 when executing monthname(Tmonth)



Here is the code



Thanks in advance




Code:



<%
Tmonth = Month(Date())
tnow = Month(now)
adder= Request.QueryString("calnav")
counted= Request.QueryString("count")

if adder = "" then
counted = "0"
Tmonth = Month(Date()) + counted
Response.Write("loop 1")
elseif adder = "plus" and Tmonth = 12 then
counted = 0
Tmonth = 1
elseif adder = "plus" then
counted = counted + 1
Response.Write(counted & " pos <br>")
Response.Write("loop 2 <br>")
elseif adder = "minus" and Tmonth = 1 then
counted = 0
Tmonth = 12
elseif adder = "minus" then
counted = counted - 1
Response.Write(counted & "neg")
Response.Write("loop 3")
end if
%>
<html>
<body>
<a href="shortcalxp.asp?calnav=minus&count=<%=counted%>"><-- (last month)</a>
<a href="shortcalxp.asp?calnav=plus&count=<%=counted%>">--> (next month)</a>
</body>
</html>



    
Guest


What are you trying to do? The code isn't contained within <% tags, either.

Was this answer helpful ? Yes No   
Guest


the quotes i forgot to copy out.



When the "-->" (next month) link is clicked the code cycles from the current month number "Tmonth = Month(Date())" (month 9 now) to 12 (December). When Tmonth = 12 then Tmonth should be set to 1 (january). The opposite is supposed to happen when <--last month is clicked and Tmonth = 1, it should set Tmonth = 12 jan to Dec.



Thanks

Was this answer helpful ? Yes No   
Guest


For a start it's a bit difficult to make out exactly what you want. I think i have an idea. What happens at the momment?

Was this answer helpful ? Yes No   
Guest


Is this what you want?


Code:



<%
If IsEmpty(Request("m")) Then
TMonth = Month(Date)
Else
TMonth = Month(DateAdd("m",Request("m"),TMonth))
End If
%>
<html>
<body>

<h1><%= MonthName(TMonth) %></h1>
<p><a href="shortcalxp.asp?m=-1"><-- LastMonth</a>
<br><a href="shortcalxp.asp?m=1">Next Month --></a></p>

</body>
</html>






Actually, this is rubbish, forget that.


Was this answer helpful ? Yes No   
Guest


Try this, instead:


Code:



<%
If IsEmpty(Request("m")) Then
TMonth = Month(Date)
Else
TMonth = Month(DateAdd("m",Request("m"),"1 " & MonthName(Request("d")) & " " & Year(Date)))
End If
%>
<html>
<body>

<h1><%= MonthName(TMonth) %></h1>

<p><a href="tmonth.asp?d=<%= TMonth %>&m=-1"><-- LastMonth</a>
<br><a href="tmonth.asp?d=<%= TMonth %>&m=1">Next Month --></a></p>

</body>
</html>



Was this answer helpful ? Yes No   
Guest


you're making things much more complex than they should be.

instead of having minus/plus in the link, have the actual month in there...


ASP Code:
















Original
- ASP Code


  1.  
  2.  Dim calMonth
  3.  calMonth=Request("month")
  4.  If IsNumeric(calMonth) Then
  5.     calMonth=CInt(calMonth)
  6.  Else 
  7.     calMonth=Month(Now)
  8.  End If
  9.  '.....use calMonth to display calendar.......
  10.  '.......
  11.  '.......
  12.  If calMonth>1 Then
  13.     Response.Write("<a href=""?month="&(calMonth-1)&"""><-- (previous month)</a>")
  14.  End If
  15.  If calMonth<12 Then
  16.     Response.Write(" <a href=""?month="&(calMonth+1)&""">Next Month --></a>")
  17.  End If



Was this answer helpful ? Yes No   
Guest


that is spot on. thanks a million. This is what i originally started to make it work with, by only passing a 1 or -1 through the url but got frustrated with it and ended up with the mess i posted before.



There is one thing, i assumed it would be easy to make it jump from dec 05 to jan 06, I tried to add another else if condition but it just seems to be ignoring it, why is that?



I created a var. datum and then added extra conditions to the if / else statement that add or subtract from the year.



But they don't work. I tried to look up how to handle IF AND conditions and followed the example but i cant see why it doesnt work, I would really like to understand why it doesnt work as I want to use similar arguments in the future.



Thanks




Code:



<%
dim datum
datum = year(date)
If IsEmpty(Request("m")) Then
TMonth = Month(Date)
Elseif Tmonth = 12 and m = 1 then
datum = DateAdd("yyyy",Request("m"),"1 " & MonthName(Request("d")) & " " & datum)
Elseif Tmonth = 1 and m = -1 then
datum = DateAdd("yyyy",Request("m"),"1 " & MonthName(Request("d")) & " " & datum)
Else
TMonth = Month(DateAdd("m",Request("m"),"1 " & MonthName(Request("d")) & " " & datum))
End If
%>



Was this answer helpful ? Yes No   
Guest


have you read my reply at all??

Was this answer helpful ? Yes No   
Guest


Sorry I missed it, i had a look and i would like it to detect the current month and start from there, then inc / decr from there. I like the fact that you can only go forward from a date.



This is for a small events calander I have been trying to develope, so this variable will be passed in to an SQL query to select the current month and the navigation is to see whats coming up.



Thats why i also want it to jump a year from dec-jan. Will specifying the var type help in any specific way? In my ignorance i cannot see any advantage.



Thanks

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved