Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable Image display in If statements

Status
Not open for further replies.

meltingpot

Technical User
May 11, 2004
118
GB

Hi ... The following code warns me via an image that a date is greater than a year old.

It works great but im looking to put a third image warning that the "safety_insp" date field in MSAccess is greater than '335' days old displaying the image file 'amber.gif'

Also at the same time if the data field is empty display the text 'n/a'.

Ive made no headway as im a beginer ..Ive tied myself in knots !!!!!!!!
Any ideas out there .... many thanks

<%
Dim sBoat, sElapsed
sBoat = b_status("name") & ""
sElapsed= DateDiff("d", b_status("safety_insp"), date())
if iElapsed <= 365 then
'1 year, 365 days or less
Response.Write "<img src='green.gif'>"
else
'More than 365 days
Response.Write "<img src='red.gif'>"
end if
%>
 
You can nest a couple if statements.
Assuming your data field is the name field, and you have a valid connection to the database,

<%
Dim sBoat, sElapsed
sBoat = b_status("name") & ""
sElapsed= DateDiff("d", b_status("safety_insp"), date())

If IsNull(sBoat)Then
Response.Write "n/a"
Else

If sElasped >= 335 And sElasped <365 Then
Response.Write "<img src='amber.gif'>"
ElseIf sElasped >= 365 Then
Response.Write "<img src='red.gif'>"
Else
Response.Write "<img src='green.gif'>"
End If
End If

%>

Paul
 
Hi .. thanks for the code. It only returns the image 'on.gif' in all date situations. I have put dummy data to emulate the required date conditions. The 'IsNull' is working though. Ive had to put a 'x' in front of Elasped as the are more than one of these on the page. Ive palyed around a bit but cannot get t he iamges to react to the data .... amny thanks for your efforts :)

<%
Dim xBoat, xElapsed
xBoat = b_status("name") & ""
xElapsed= DateDiff("d", b_status("scv2_ann"), date())

If IsNull(b_status("scv2_ann"))Then
Response.Write "n/a"
Else

If xElasped >=335 And xElasped <365 Then
Response.Write "<img src='amber.jpg'>"
ElseIf xElasped <=365 Then
Response.Write "<img src='on.gif'>"
Else
Response.Write "<img src='a.jpg'>"
End If
End If
%>
 
The ElseIf line needs some adjustment

you have
Code:
ElseIf xElasped [blue]<[/blue]= 365
and it should be
Code:
ElseIf xElasped [blue]>[/blue]= 365

Try changing that and see if it helps.

Paul

 

Hey PaulBricker your a genius !!!

Finshed up with this and it works great - It always looks simple when somebody else does it for you ... Many thanks Matey ;-)
Final code

<%
Dim xBoat,svcElapsed
xBoat = b_status("name") & ""
svcElapsed= DateDiff("d", b_status("scv2_ann"), Date())
If IsNull(b_status("scv2_ann"))Then
Response.Write "No Dates"
Else

if svcElapsed >=335 And svcElapsed <365 Then
Response.Write "<img src='wa.gif'>"
ElseIf svcElapsed <=365 Then
Response.Write "<img src='on.gif'>"
Else
Response.Write "<img src='off.gif'>"
End If
End If
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top