?
Solved

NULL Values Displayed in a Function

Posted on 2013-01-26
8
Medium Priority
?
340 Views
Last Modified: 2013-01-27
I've got a test page here showing null start and end times where it should say 'tbc'.

Here's the output syntax:

<% if isnull(rs("ca_starttime").Value) then %>tbc<% else %><%=Right("00" & hour(rs("ca_starttime")), 2)%>:<%=Right("00" & minute(rs("ca_starttime")), 2)%><% end if %>

Open in new window


And here's where it's entered:

<% CreateTimeSelectionBox "starttime", NULL, False %>

Open in new window


If someone could please show me exactly what needs to be written in the output syntax it'd be much appreciated.

Many thanks.
0
Comment
Question by:UName10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 1600 total points
ID: 38823468
<div class="time">At: 00:00</div>
Formatting Time
<%
 if isnull(rs("ca_starttime").Value) then
     response.write "tbc"
     else
     response.write formatdatetime(rs("ca_starttime"),4) '00:00
  end if
%>

If you want to do it the hard way....

<%
 if isnull(rs("ca_starttime").Value) then
     response.write "tbc"
     else
     
      theHour=hour(rs("ca_starttime"))
      theMin=minute(rs("ca_starttime"))
      if theHour<10 then
          theHour="0"&theHour
      end if
      if theMin<10 then
          theMin="0"&theMin
      end if
      response.write theHour&":"&theMin
     
  end if
%>
0
 

Author Comment

by:UName10
ID: 38823945
Hi Padas,

Many thanks for the reply. Could you confirm what I should write as the value as I didn't have to do that before?  It's not working with .Value... I.e. It's hours and minutes, but we can't use both.. Just got confused.

Many thanks again.
0
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 400 total points
ID: 38823964
It looks to me that there are no real NULL values. Taking padas's code, you could add a replace assuming you will never have an event actually starting or ending at 00:00
response.write Replace(formatdatetime(rs("ca_starttime"),4), "00:00", "tbc") 

Open in new window

However, the NULL database value is in fact used for this specifically, to stand out from values that are accidentally 0 (or 00:00 in this case), so you would need to adjust your insert/update process. I would give you an example but I think it's important to realize first that with your current admin pages (posted in an earlier question) it is not possible to make that distinction. You would need to add a checkbox for example or make it possible to leave the time empty, and of course if you choose 00:00 as empty then using the replace is just as good.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:UName10
ID: 38823992
Ah yes that's the one - it isn't actually NULL, which is why I was trying to work around it, but knowing it wasn't right.. Yes we have checkboxes for other areas; and makes it more difficult..

Thanks for explaining, that makes sense. I'll have a go with that and see how I get on.

Many thanks.
0
 

Author Comment

by:UName10
ID: 38824001
Hi Robert,

Just a question, how do you think would have been the best way to do it; could the admin pages you saw before be written better? Not sure how to explain it, but it does seem we have to do work around too many times.

I.e. if we wanted to make that distinction, what would be the best way to do it?

Could we have a default NULL value for each time select which is changed only when a time is selected, maybe specify it in the function?

This was the admin code bit:

                .addparam "ca_starttime","","'"&getform("starttime_Hour") & ":" & Right("00" & getform("starttime_Min"), 2) & "'"
		.addparam "ca_endtime","","'"&getform("endtime_Hour") & ":" & Right("00" & getform("endtime_Min"), 2) & "'"

Open in new window



I can do the 00:00 for now (although a midnight start or finish wouldn't work then)..

I'll get there in the end!

Many thanks.
0
 

Author Closing Comment

by:UName10
ID: 38824016
Thank you both for your replies. As you both contributed, Padas being the main and Robert helping me recall the no NULL values.

The solution works well.
0
 

Author Comment

by:UName10
ID: 38824019
Oh and please don't worry Robert about the other queries - I need to learn more I which I'm keen to do. I'll get there...

Many thanks.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38824024
There's a link here with another question you asked. If you use a javascript 'popup' to choose the time it may have to be changed completely.

But in general, with your 2 select boxes for hour and minutes, you could for example add a first default option "--" in both, for example with value -1 and in the code check for it and insert NULL in the database. Then the code as you posted initially in this question will work.

One more remark: you may want to check first if the helper class/functions you use are in fact capable of inserting NULL values.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question