WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Verify/Retrieve is a Numeric Value

Summary: Sometimes you want to verify that the data you enter really is a number. If it isn't default the value to 0.
 
Keywords: CDBL
CHECK
CINT
CLNG
FIXNUMBER
ISNUMERIC
NUMBER
NUMERIC
VALIDATION
Applicable Software: Active Server Pages .NET (ASP.NET)
Visual Basic .NET (VB.NET)
 
Body:

It's important to validate that data is what you expect it to be. This function takes a parameter and if it is a number, it converts it to a double and returns it. If it is not a number, it returns 0. For the classic ASP/VBScript people out there, there is a VBScript version of this FixNumber function.

Public Shared Function FixNumber(numberToFix As Object) As Double

	Dim ret As String
	Dim out As Double
		
		ret = CType(numberToFix, String)

		Try
			out = Double.Parse(ret)
		Catch x As FormatException
			out = 0
		End Try
		
		Return out

End Function

To use it, you would do:

Dim id As Integer = FixNumber(Request.Params("id"))

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 12/21/2005 2:16:35 PM

Rate this article: Average: n/a
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.