Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 24th, 2004, 06:29 AM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

Reply With Quote
  #2 (permalink)  
Old March 24th, 2004, 11:26 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Johannesburg, , South Africa.
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

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
Reply With Quote
  #3 (permalink)  
Old March 24th, 2004, 02:19 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old March 24th, 2004, 03:11 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: Johannesburg, , South Africa.
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

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()
Reply With Quote
  #5 (permalink)  
Old March 24th, 2004, 07:04 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #6 (permalink)  
Old April 1st, 2004, 01:30 AM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #7 (permalink)  
Old April 1st, 2004, 04:03 AM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Reply With Quote
  #8 (permalink)  
Old April 1st, 2004, 04:50 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
  #9 (permalink)  
Old April 2nd, 2004, 08:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
Reply With Quote
  #10 (permalink)  
Old April 3rd, 2004, 05:10 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding last day of a month John Anthony Access VBA 9 October 6th, 2008 03:27 PM
get year,month,day,hour... kobystud C# 1 July 16th, 2004 04:45 PM
1st Week-Day of the Month ticktack Classic ASP Basics 2 January 19th, 2004 10:01 AM



All times are GMT -4. The time now is 11:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.