Solved

NULL Values Displayed in a Function

Posted on 2013-01-26
8
315 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
  • 5
  • 2
8 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 400 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 100 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now