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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a better way? lot's of end if's 1

Status
Not open for further replies.

craigey

Technical User
Apr 18, 2002
510
GB
Is there a better way to check these recordsets for null values? I though I could use a loop of some sort, but the recordsets are not necessarily displayed in the same order each time they are used. Any ideas?

Code:
<%
%>
<!--#include file ="header.asp"-->
<%
on error resume next
tempforcecode = RS("force_code")
if isnull(tempforcecode) then
tempforcecode = "-"
end if
tempforcename = RS("force_name")
if isnull(tempforcename) then
tempforcename = "-"
end if
templocation = RS("force_location")
if isnull(templocation) then
templocation = "-"
end if
tempaddress = RS("address")
if isnull(tempaddress) then
tempaddress = "-"
end if
tempfirstname = rs("first_name")
if isnull(tempfirstname) then
temp firstname = "-"
end if
templastname = rs("last_name")
if isnull(templastname) then
templastname = "-"
end if
tempext = rs("extension")
if isnull(tempext) then 
tempext = "-"
end if
tempmobile = rs("Mobile_Phone_Number")
if isnull(tempmobile) then
tempmobile = "-"
end if
tempoffice = rs("Office_Phone_Number")
if isnull(tempoffice) then
tempoffice = "-"
end if
tempemail = rs("email_address")
if isnull(tempemail) then
tempemail = "-"
end if
tempcontracttype = RS("Contract_Type")
if isnull(tempcontracttype) then
tempcontracttype = "-"
end if
tempdirection = RS("directions")
if isnull(tempdirection) then
tempdirection = "-"
end if
temppostcode = RS("Post_code")
if isnull(temppostcode) then
temppostcode = "-"
end if
tempfirstname = RScheck3("first_Name")
if isnull(tempfirstname) then
tempfirstname = "-"
end if
tempsurname = RScheck3("Surname")
if isnull(tempsurname) then
tempsurname = "-"
end if
tempoffice = RScheck3("Office")
if isnull(tempoffice) then
tempoffice = "-" 
end if
tempofficenum = RScheck3("Office_Num")
if isnull(tempofficenum) then
tempofficenum = "-"
end if
tempmobilenum = RScheck3("Mobile_num")
if isnull(tempmobilenum) then
tempmobilenum = "-"
end if
tempemail = RScheck3("email")
if isnull(tempemail) then
tempemail = "-"
end if
tempnotes = RS("Notes")
if isnull(tempnotes) then
tempnotes = "-"
end if
tempcontractexpiry = RS("Contract_Expiry")
if isnull(tempcontractexpiry) then
tempcontractexpiry = "-"
end if
%>
 
write a function that returns the necessary string in the event of a null. EG:

Code:
Function NullToString(Val,RetVal)
If Isnull(Val) Then
NullToString=RetVal
Else
NullToString=Val
End If
End Function

Then you would call it for each field, eg:

Code:
tempforcecode = NullToString(RS("force_code"),"-")
 
great stuff!

Thanks. I thought there had to be a better way. I think I'll have to research functions to help clean my code.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top