Jump to content

How to pass a null and another value into a function

- - - - -

  • Please log in to reply
1 reply to this topic

#1
vertigo262

vertigo262

    Newbie

  • Members
  • Pip
  • 4 posts
Ok, I keep running into this problem

In my aspx I am calling a simple function.

But the problem is, that the function is either, string, integer, etc.

If there's null's in the data, the function explodes because it's set to a string or integer, etc.

How can I make the function accept both a null, and another data type so that I can

write some if then's to do different things if it is null or another data type.

Here is the code to give you an idea

#
# .aspx code
#
# <%# GetRatingFormat(Container.DataItem("Rating") %>
#
#
# .vb code
#
# Function GetRatingFormat(ByVal UserRating As Decimal) As String
#
# If IsNothing(UserRating) Or IsDBNull(UserRating) Then
# Return "Not Yet Rated"
# Else
# Return Format(UserRating, "0.0") & "%"
# End If
#
#
# End Function
#
#
#
UserRating needs to accept both null and decimal

any help would be greatly appreciated

#2
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
String class has the NullOrEmpty Static method use it before you update Db about the rating is made(4 Stars etc)

in C# that would be:
public String FormatRating(Decimal numRated){
return String.IsNullorEmpty(numRated.ToString())?"Not Rated Yet":numRated.ToString("0%");
}





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users