Search code examples
vbscriptasp-classic

Show image based on date VB Script


I am extremely new to VB Script, and any help is extremely appreciated.

I currently have 4 images that need to be displayed based on the date. I have named each image as 1,2,3 and 4. I am using the date function to display this but I am getting a 500 error message. If there is a better way to accomplish this with VBScript please let me know. The images are in a folder specified in the path for the src inside the div and the extension of the images is PNG.

   <%@LANGUAGE="VBSCRIPT"%> 

<%
Dim CurDate

'CurDate = Month(DATE)
'CurDate =("2018-11-01")
 CurDate =(DATE)    

response.write(CurDate) 

If CurDate = "2018-10-30" THEN
    CurDate = 1
If CurDate = "2018-11-01" THEN
    CurDate = 2

If CurDate = "2018-11-02" THEN
    CurDate = 3

Else CureDate = 4

End If

%>  

     HTML Below


  <div style="padding-left:10px;text-align:center;">
    <img alt="Image- Displaying" border="0" src="http://Path/Default/Pane/imgFolder/<%=CurDate%>.png">
</div> 

Solution

  • I think your problem is with your if/else/then.

    <%@LANGUAGE="VBSCRIPT"%> 
    
    <%
    Dim CurDate
    
    'CurDate = Month(DATE)
    'CurDate =("2018-11-01")
     CurDate =(DATE)    
    
    response.write(CurDate) 
    
    If CurDate = "2018-10-30" THEN
        CurDate = 1
    elseIf CurDate = "2018-11-01" THEN
        CurDate = 2
    elseIf CurDate = "2018-11-02" THEN
        CurDate = 3
    Else
        CurDate = 4
    End If
    %>  
    
         HTML Below
    
    
    <div style="padding-left:10px;text-align:center;">
      <img alt="Image- Displaying" border="0" src="http://Path/Default/Pane/imgFolder/<%=CurDate%>.png">
    </div>