Forum Moderators: open

Message Too Old, No Replies

Need basic conditional statement help

If then roll back time else if then roll back time and date.

         

Stuperfied

1:00 pm on Apr 2, 2005 (gmt 0)

10+ Year Member



Hi,

Im making a Clan War page for a game site which is intended to notify members of up and coming events. I want it to adjust to their time zone so as to avoid confusion.

Members can select their time zone in their profile which updates on the database. Administrators will enter the date and time relevant to their own time zone and the page will convert it to GMT before saving it to the database. When a member views it, the page will convert the date and time to the appropriate time zone.

Now if you can understand all that, here's the code so far for the view page. I havent even started on the Clan War admin page yet.


Dim membertimezone
Dim gmtwardate
Dim gmtwartime
Dim showwardate
Dim showwartime
Dim GMT1
Dim GMT2
Dim GMT3
Dim GMT4
Dim GMT5
Dim GMT6
Dim GMT7
Dim GMT8
Dim GMT9
Dim GMT10
Dim GMT11
Dim GMT12
Dim GMT13
Dim GMT14
Dim GMT15
Dim GMT16
Dim GMT17
Dim GMT18
Dim GMT19
Dim GMT20
Dim GMT21
Dim GMT22
Dim GMT23
Dim GMT24
Dim GMT25
Dim GMT26
Dim GMT27
Dim GMT28
Dim GMT29
Dim GMT30
Dim GMT31
Dim GMT32

membertimezone = (rsMembers.Fields.Item("Time Zone").Value)
gmtwardate = (rsClanWars.Fields.Item("Date").Value)
gmtwartime = (rsClanWars.Fields.Item("Time").Value)
GMT1 = "(GMT -12:00) Eniwetok, Kwajalein"
GMT2 = "(GMT -11:00) Midway Islands, Samoa"
GMT3 = "(GMT -10:00) Hawaii"
GMT4 = "(GMT -09:00) Alaska"
GMT5 = "(GMT -08:00) Tijuana, Los Angeles, Seattle, Vancouver"
GMT6 = "(GMT -07:00) Arizona, Denver, Salt Lake City, Calgary"
GMT7 = "(GMT -06:00) Mexico City, Saskatchewan, Central America"
GMT8 = "(GMT -05:00) Bogota, Lima, New York, Toronto, Montreal, Quebec"
GMT9 = "(GMT -04:00) Caracas, La Paz, Santiago"
GMT10 = "(GMT -03:30) Newfoundland"
GMT11 = "(GMT -03:00) Brazil, Buenos Aires, Georgetown, Greenland"
GMT12 = "(GMT -02:00) Mid-Atlantic"
GMT13 = "(GMT -01:00) Azores, Cape Verde Islands"
GMT14 = "(GMT) Casablanca, Monrovia, Dublin, Edinburgh, Lisbon, London"
GMT15 = "(GMT +01:00) Amsterdam, Berlin, Berne, Rome, Stockholm, Paris"
GMT16 = "(GMT +02:00) Athens, Istanbul, Minsk, Cairo, Jerusalem"
GMT17 = "(GMT +03:00) Bagdad, Moscow, Nairobi"
GMT18 = "(GMT +03:30) Teheran"
GMT19 = "(GMT +04:00) Muscat, Tiflis"
GMT20 = "(GMT +04:30) Kabul"
GMT21 = "(GMT +05:00) Islamabad"
GMT22 = "(GMT +05:30) Calcutta, New Delhi"
GMT23 = "(GMT +05:45) Katmandu"
GMT24 = "(GMT +06:00) Almaty, Nowosibirsk, Dhaka"
GMT25 = "(GMT +06:30) Rangun"
GMT26 = "(GMT +07:00) Bangkok, Hanoi, Jakarta"
GMT27 = "(GMT +08:00) Beijing, Perth, Singapore, Hong Kong, Taipei"
GMT28 = "(GMT +09:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk"
GMT29 = "(GMT +09:30) Adelaide, Darwin"
GMT30 = "(GMT +10:00) Brisbane, Canberra, Melbourne, Sydney, Vladivostok"
GMT31 = "(GMT +11:00) Solomon Islands, New Caledonia"
GMT32 = "(GMT +12:00) Auckland, Wellington, Fiji, Kamchatka"

If membertimezone = GMT1 then
' in here, showwartime should = gmtwartime - 12h
' then if result is -1 day then showwardate should = gmtwardate - 1d.
Else If membertimezone = GMT2 then

Else If membertimezone = GMT3 then

Else If membertimezone = GMT4 then

Else If membertimezone = GMT5 then

Else If membertimezone = GMT6 then

Else If membertimezone = GMT7 then

Else If membertimezone = GMT8 then

Else If membertimezone = GMT9 then

Else If membertimezone = GMT10 then

Else If membertimezone = GMT11 then

Else If membertimezone = GMT12 then

Else If membertimezone = GMT13 then

Else If membertimezone = GMT14 then

Else If membertimezone = GMT15 then

Else If membertimezone = GMT16 then

Else If membertimezone = GMT17 then

Else If membertimezone = GMT18 then

Else If membertimezone = GMT19 then

Else If membertimezone = GMT20 then

Else If membertimezone = GMT21 then

Else If membertimezone = GMT22 then

Else If membertimezone = GMT23 then

Else If membertimezone = GMT24 then

Else If membertimezone = GMT25 then

Else If membertimezone = GMT26 then

Else If membertimezone = GMT27 then

Else If membertimezone = GMT28 then

Else If membertimezone = GMT29 then

Else If membertimezone = GMT30 then

Else If membertimezone = GMT31 then

Else If membertimezone = GMT32 then

End If


The remarks show where im stuck. If anyone knows how to do it or can even suggest some refinements in laymens terms, I would very much appreciate it.

Thanks.

emsaw

8:33 pm on Apr 3, 2005 (gmt 0)

10+ Year Member



Sorry, I couldn't figure out why the formatting/tabs are not translating in this post, so you'll have to cut and paste this and re-format it to make it more readable. But this should do what you want, and you should be able to integrate whatever portions you need into your script. Just take the whole thing below, as it's fully functional, and drop it into your wwwroot to test it out.

Hope this helps!

-Mark


<%@ Language="VBScript" %>
<% OPTION EXPLICIT %>
<%
Function populateDDL()
Dim timeZone, timeZones
Dim fieldName


Set timeZones = CreateObject("Scripting.Dictionary")


timeZones.Add "-", "Please Select Time Zone"
timeZones.Add "-12.0", "(GMT -12:00) Eniwetok, Kwajalein"
timeZones.Add "-11.0", "(GMT -11:00) Midway Islands, Samoa"
timeZones.Add "-10.0", "(GMT -10:00) Hawaii"
timeZones.Add "-3.5", "(GMT -03:30) Newfoundland"


For Each timeZone In timeZones
Response.Write "<OPTION VALUE=""" & timeZone & """"


fieldName = "tzones"
If Not( IsNull (Request.Form(fieldName))) Then
If( Len(Request.Form(fieldName)) > 0) Then
Response.Write " SELECTED "
End If
End If


Response.Write ">" & timeZones.Item(timeZone) & "</OPTION>"
Next
End Function


Function getSelection()
Dim fieldName, validSelection


fieldName = "tzones"
If Not( IsNull (Request.Form(fieldName))) Then
If( Len(Request.Form(fieldName)) > 0) Then
If( Request.Form(fieldName) = "-" ) Then
validSelection = false
Else
validSelection = true
End If


If (validSelection) then
Response.Write "You selected <b>" & fieldName & " : " & Request.Form(fieldName) & "</b>"
Else
Response.Write "Please select an option below"
End If
' Do your DB work here to record the timezone
End If
End If
End Function


Function getOffSetTime()
Dim fieldName, fieldName2
Dim warTime, offsetTime


fieldName = "warDateTime"
fieldName2 = "tzones"
If Not( IsNull (Request.Form(fieldName))) Then
If( Len(Request.Form(fieldName)) > 0) Then
If (IsDate(Request.Form(fieldName))) Then
warTime = CDate(Request.Form(fieldName))


If Not( IsNull (Request.Form(fieldName2))) Then
If( Len(Request.Form(fieldName2)) > 0) Then
offsetTime = DateAdd("N", Request.Form(fieldName2) * 60, warTime)


Response.Write "<br><br>Standardized Time for this event is: " & CStr(offsetTime) + "<br><br>"
End If
End If
End If
End If
End If


End Function


getSelection()
getOffSetTime()
%>
<html>
<head>
<title>Time Zone Select</title></head>
<body>
<FORM ACTION="<%= Request.ServerVariables("SCRIPT_NAME") %>" METHOD="post" NAME="testForm">
War Time:<input type="text" id="warDateTime" name="warDateTime" value="<% = Request.Form("warDateTime") %>">
(Enter a full date/time like 04/03/2005 03:30 PM)
<br>
Time Zone:<select name="tzones" id="tzones">
<% = populateDDL() %>
</select>
<br>
<br>
<input type="submit" id="submitData" name="submitData" value="Submit"></input>
</FORM>
</body>
</html>

emsaw

8:38 pm on Apr 3, 2005 (gmt 0)

10+ Year Member



Saw a small mistake,

Please replace the corresponding lines of populateDDL():


fieldName = "tzones"
If Not( IsNull (Request.Form(fieldName))) Then
If( Len(Request.Form(fieldName)) > 0) Then
If(Request.Form(fieldName) = timeZone) Then
Response.Write " SELECTED "
End If
End If
End If

Stuperfied

2:12 am on Apr 4, 2005 (gmt 0)

10+ Year Member



Thank you very much emsaw, It works and I have put it up on the server as a temporary measure until I can convert it to what we require. I still need to add the other time zones but im about to go out now so dont have time at the moment.

The finished product will work in 3 stages.
1. The user selects their time zone and date format in their profile (should probably allow for time format too) which is saved with their login information.
2. The admins go to a page called ClanWarAdmin and enter the date and time of the next few clan wars and who they are against which will be saved to the database in a table called Clan_Wars.
3. Any user will login and goto the clan wars page to view the dates and times relative to their own time zone.

I will let you know if I have any further problems and how it all turns out.

Stuperfied

9:38 am on Apr 28, 2005 (gmt 0)

10+ Year Member



I had to remove the option explicit statement for it to work on my server but when I put it on the AVS Networks server (with or without the option explicit statement), it doesnt work. Any ideas why?

mattglet

12:39 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'd shouldn't ever have to make something work by removing Option Explicit.

What's the error you're getting?

Edit:
The problem is most likely happening because you're using global references inside your functions. The reason it worked without Option Explicit is because you took away your scope. I highly suggest you pass in the values you want to use as arguments, in your getOffSetTime() function. Also, you shouldn't refer to a collection object (Request.Form(whatever)) more than once, it hampers your performance efficiency. Store the value in a variable, and use it as such.

I think you need to rethink the design of your functions, and your implementation of them.

Stuperfied

4:02 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



Thank you for your reply. I will attempt to make the modifications you suggested in the morning, for now I need to get some sleep because its 2am here.