Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2007, 02:02 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default IsNumeric Query

Hi,

Within an e-commerce website, the cart summary page allows customers to

change the quantities of ordered items. Within this page I want to add the

following restrictions :

* Restrict the value e.g. > 0 and < 10 ?
* Stop negative values
* Stop non-numeric characters.

I've used the following code (asp.net 1.1, vb.net 2003) to restrict the

first two, which works fine :

  
Code:
  If (intQuantity <=0 OR intQuantity >10) Then


intQuantity references a textbox that the customer can edit the quantity of

the item they have selected. However to stop non-numeric characters I

thought of using the "IsNumeric" function. What I want to say is if the

value inputted is non-numeric thenxxxx. So I used the following code :

Code:
   If (IsNumeric <> (txtQuantity.Text)) OR (intQuantity <=0 OR 

intQuantity >10) Then
which then results in an error :

Compilation Error
Description: An error occurred during the compilation of a resource

required to service this request. Please review the following specific

error details and modify your source code appropriately.

Compiler Error Message: BC30455: Argument not specified for parameter

'Expression' of 'Public Function IsNumeric(Expression As Object) As

Boolean'.

Source Error:



Line 205:
Line 206: Line 207: If (IsNumeric <> (txtQuantity.Text))

OR (intQuantity <=0 OR intQuantity >10) Then
Line 208: Line 209: 'Display message advising item

is low in stock


Any ideas on how I can overcome this ?

Thanks,

 
Old June 12th, 2007, 02:39 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

If Not IsNumeric(txtQuantity.Text) Then
                Throw New Exception("Only numbers are allowed for quantity.")
            End If

 
Old June 12th, 2007, 03:46 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

>< As rich pointed out, IsNumeric is a function hence you have to supply a value to it IsNumeric(Value); is numeric returns a bool value.

I, however, would not Throw an exception here, rather just handle it with a friendly message or something to that effect.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 13th, 2007, 02:40 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks both

In the end I changed tatics and used an regular expression validator to solve this issue - thanks again for your inputs....






Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
IsNumeric Bug thicks VB.NET 1 June 26th, 2007 06:55 PM
IsNumeric ? Berggreen C# 1 June 21st, 2006 07:05 PM
ISNUMERIC function ram2098 SQL Server 2000 2 November 3rd, 2003 03:58 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.