 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 24th, 2004, 06:29 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Asp day of month display
I have an asp web page, where a small javascript goes to a specific directory, reads the daily image, and displays the image.
The images have names 1.jpg, 2.jpg, 3.jpg etc untill 31.jpg. 31 images for the 31 days of month.
The javascript is the following:
var dt = new Date(); var hr = dt.getDate(); var msg="<IMG SRC=29dailypic/"+hr+".jpg>"; document.write(msg);
I want to do the same task in asp.
This has many advantages because javascript is client-side and if a visitor change the current date of his machine to a future day, he will instantly view the image I wanted to be visible in the future.
Asp is server-side running, so nobody would do such a thing.
I do not bother if the asp script looks at a directory for 1-365 jpgs for 365 days of year(yearly basis).
Can you please give me the asp code to replace this javascript?
|
|

March 24th, 2004, 11:26 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
One way to do this is to split your date to get the day:
Try something like this:
<%
date_string = "10-03-2004" 'Or use Date()
date_parts = Split(date_string, "-")
' the - will be ur seperator depending on server setting
day_part = date_parts(0)
month_part = date_parts(1)
year_part = date_parts(2)
'Then u could use a Case e.g
Select Case(day_part)
Case "01"
ImgVar = 1.jpg
Case "02"
ImgVar = 2.jpg
'etc
End Select
%>
You could use ImgVar as a variable in ur HTML to display the image.
The syntax above might not be 100% but this might point you in the right direction... Let me know if you need more detail
Regards
Marnus
|
|

March 24th, 2004, 02:19 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response.
I am not having programming experience so it would be nice if you could be more specific.
Suppose that the images are stored in a folder named 'main/dailypic' .
Where do we declare this?
The '10-3-2004' you wrote above, I replaced it with Date().
What do you mean 'will be ur seperator depending on server setting'? How do I discover this to tell it to you to fix it?
That's the code I tried:
<%
date_string = Date() 'Or use Date()
date_parts = Split(date_string, "-")
' the - will be ur seperator depending on server setting
day_part = date_parts(0)
month_part = date_parts(1)
year_part = date_parts(2)
'Then u could use a Case e.g
Select Case(day_part)
Case "01"
ImgVar = 1.jpg
Case "24"
ImgVar = 24.jpg
'etc
End Select
%>
That's the error Internet explorer gave me:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/index.asp, line 240, column 11
ImgVar = 1.jpg
----------^
Can we make it better?
Thanks in advance
|
|

March 24th, 2004, 03:11 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Copy this onto a blank asp page
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
date_string = "03-04-2004" 'Or use Date()
date_parts = Split(date_string, "-")
' the - will be ur seperator depending on server setting
day_part = date_parts(0)
month_part = date_parts(1)
year_part = date_parts(2)
'Then u could use a Case e.g
Dim day_part
Select Case lcase(day_part)
CASE "03"
Img1 = "main/dailypic/3.gif"
Case "06"
Img1 = "main/dailypic/6.gif"
Case Else
response.write("None")
End Select
response.write(Img1)
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<img src=<%=Img1%>>
</body>
</html>
Play around with the date_string and see how the image changes. To see what the date format in on your server do the following:
Open Notepad and paste the following in the file:
a = now()
msgbox(a)
Save the file as something.vbs and run it. It will give you the date and time format. See what your seperator is and also if the day is first middel or last... Change the code acordingly when changing the date_string to Date()
|
|

March 24th, 2004, 07:04 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I made the appropriate changes as you told me and now this brand new asp works fine, and makes me happy.
Your help was great.
Thank you very much.
|
|

April 1st, 2004, 01:30 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Unfortunatelly I face a problem.
After some days of smooth running, the asp didn't work.
What I mean? It displayed a - character and the not found image sign(a box with an x in it).
It is a very strange thing.
I saw it from on pc and then it is not displayed.
I saw it from another pc, it is displayed.
The script you gave me is almost simple and the case of one day is almost similar with the next ones. I cannot find a difference in these days to explain why this happens. Script is ok (no bad coding-case for every day of month), images are in their folder.
Why this happens? What can we do to fix it?
Thanks in advance
|
|

April 1st, 2004, 04:03 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The helpdesk of my hosting company told me there is a bug in asp language.
The server do not return always the same date! One time gives 09 April, the other time gives 9 April, so our script could not run smoothly.
So, they told me to add 9 cases more, without the 0(zero) in front of the main number.
What do you think about it? Is it the solution to the problem?
Thanks in advance
|
|

April 1st, 2004, 04:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
A bug in ASP? Personally, I don't trust help desks to much, especially when they give these kinds of answer. Can you ask for more information? e.g. a page on the Microsoft site or a Knowledge Base article ID? It would be fun to see what they come up with.
Anyway, what you can do is convert your date parts to number and compare against that:
Code:
' CInt converts text to a number (an Int)
day_part = CInt(date_parts(0))
month_part = CInt(date_parts(1))
year_part = CInt(date_parts(2))
'Then you can use Select Case with numbers too
' Dim <s>day_part</s> ' yoo should move this line up
' to before where you assign its value
Select Case day_part
Case 3
Img1 = "main/dailypic/3.gif"
Case 6
Img1 = "main/dailypic/6.gif"
Case Else
Img1 = "None"
End Select
Response.Write(Img1)
I think this will do the trick, as day_part ends up as 3, no matter whether it initially contained 03 or 3....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

April 2nd, 2004, 08:47 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I wonder why one has to use Select .. case... in this post.
As it is clear that, the original poster of the message wants to display the image that corresponds to current day, I dont see any necessity in using a select case there. It would be as simple as this.
day_part = CInt(Day(date()))
ImgName = "main/dailypic/" & date_part & ".gif"
'May be CStr() used if required
'ImgName = "main/dailypic/" & CStr(date_part) & ".gif"
Response.Write(ImgName)
Cheers!
-Vijay G
|
|

April 3rd, 2004, 05:10 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yeah, you're right. I missed the initial part of the post so I assumed that the image should only be drawn for the 6 and 9 cases, and "None" in all other situations.
Your solution is much easier and better if you need to display all images for all days, as the OP requested.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |