473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trappable Errors

Is there an error that can be raised to replace IsNumeric?

Thanks!
Jul 17 '05 #1
6 4016
> Is there an error that can be raised to replace IsNumeric?

I'm not sure what that question is supposed to mean. What is it you are
trying to do?

Rick - MVP
Jul 17 '05 #2
I want to validate textbox input. I need to make sure that there is
something entered and that the entered value is a number. I don't want
to use IsNumeric or Len(...). I want to get into trapping and handling
errors. Thanks.




"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<d4********************@comcast.com>...
Is there an error that can be raised to replace IsNumeric?


I'm not sure what that question is supposed to mean. What is it you are
trying to do?

Rick - MVP

Jul 17 '05 #3
ma******@hotmail.com (martim07) wrote in message news:<85**************************@posting.google. com>...
I want to validate textbox input. I need to make sure that there is
something entered and that the entered value is a number. I don't want
to use IsNumeric or Len(...). I want to get into trapping and handling
errors. Thanks.

It sounds like you are making things harder on yourself than
necessary.

Use the 'VAL' function: dblValue=VAL(txtBox.text)
Right out of the MSDN Library---------------------------------------
The Val function stops reading the string at the first character it
can't recognize as part of a number. Symbols and characters that are
often considered parts of numeric values, such as dollar signs and
commas, are not recognized. However, the function recognizes the radix
prefixes &O (for octal) and &H (for hexadecimal). Blanks, tabs, and
linefeed characters are stripped from the argument.

---------------------------------------------------------------------
You need decision logic to test for the returned value at some event:
if dblValue<1 then
err.raise (someErrorNum) 'Explicitly raise an error

or alternately you can:
dblResult=1/dblValue 'This will also raise an error if dblValue is
zero.

It it up to you to catch the errors.

--Steve.
Jul 17 '05 #4
> I want to validate textbox input. I need to make sure that there is
something entered and that the entered value is a number. I don't want
to use IsNumeric or Len(...). I want to get into trapping and handling
errors. Thanks.


There is no (practical) way to get VB to recognize a non-numeric input to a
TextBox as being an error without checking to see that it is not a number
and using Err.Raise to force the error. Of course, that would be silly to do
since as soon as you know it is not what you want, you can react to it then
and there without wasting VB's time forcing it to generate an error.

Checking with Len to see if anything was typed is the standard way to check
if the TextBox is empty. You might want to use Trim$ inside of the Len
function to catch instances where the **only** thing the user typed was one
or more blank spaces. As for deciding if the user's entry is a number or
not, here are two functions that I have posted in the past for similar
questions..... one is for digits only and the other is for "regular"
numbers:

Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Not Value Like "*[!0-9]*"
End Function

Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) > 0 And Value <> "." And _
Value <> vbNullString
End Function
Rick - MVP
Jul 17 '05 #5

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:3E********************@comcast.com...
I want to validate textbox input. I need to make sure that there is
something entered and that the entered value is a number. I don't want
to use IsNumeric or Len(...). I want to get into trapping and handling
errors. Thanks.
There is no (practical) way to get VB to recognize a non-numeric input to

a TextBox as being an error without checking to see that it is not a number
and using Err.Raise to force the error. Of course, that would be silly to do since as soon as you know it is not what you want, you can react to it then and there without wasting VB's time forcing it to generate an error.

Checking with Len to see if anything was typed is the standard way to check if the TextBox is empty. You might want to use Trim$ inside of the Len
function to catch instances where the **only** thing the user typed was one or more blank spaces. As for deciding if the user's entry is a number or
not, here are two functions that I have posted in the past for similar
questions..... one is for digits only and the other is for "regular"
numbers:

Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Not Value Like "*[!0-9]*"
End Function

Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) > 0 And Value <> "." And _
Value <> vbNullString
End Function
Rick - MVP

These methods all work- however I use a much simpler method..

For the text box I use the KeyPress event:
Text1_KeyPress(KeyAscii as Integer)

Select Case KeyAscii
Case 48 to 57, 8
Case Else
KeyAscii = 0
End Select

Works in that NO non-numeric input *can* be entered. 48 to 57 are the ASCII
codes for 0 through 9 and 8 is ASCII for backspace (in case user makes a
mistake? Hey... it's been known to happen!)

For the textbox event (to see if anything was written) would it not be
easier just to write:

If text1.text = "" Then
MsgBox "Write your message here"
text1.SetFocus
End If
???

Would that help you more?

Gary - MCP
Jul 17 '05 #6
See inline comments...
Function IsDigitsOnly(Value As String) As Boolean
IsDigitsOnly = Not Value Like "*[!0-9]*"
End Function

Function IsNumber(ByVal Value As String) As Boolean
' Leave the next statement out if you don't
' want to provide for plus/minus signs
If Value Like "[+-]*" Then Value = Mid$(Value, 2)
IsNumber = Not Value Like "*[!0-9.]*" And _
Not Value Like "*.*.*" And _
Len(Value) > 0 And Value <> "." And _
Value <> vbNullString
End Function
Rick - MVP

These methods all work- however I use a much simpler method..

For the text box I use the KeyPress event:
Text1_KeyPress(KeyAscii as Integer)

Select Case KeyAscii
Case 48 to 57, 8
Case Else
KeyAscii = 0
End Select

Works in that NO non-numeric input *can* be entered. 48 to 57 are the

ASCII codes for 0 through 9 and 8 is ASCII for backspace (in case user makes a
mistake? Hey... it's been known to happen!)
If you are trying to restrict entry to only numbers, the above will not
protect against the user Pasting in non-numeric characters. Two camps have
formed over data verification... the first is like your proposal, do it at
entry time; the other is let the user type what they want without bothering
them during the entry process and proof it later (which is what my functions
would be used for and, I believe, is what the OP asked for).

For the textbox event (to see if anything was written) would it not be
easier just to write:

If text1.text = "" Then
MsgBox "Write your message here"
text1.SetFocus
End If
???


While Text1.Text = "" works, believe it or not, Len(Text1.Text) = 0 executes
faster. However, I would do as I suggested in my first post and use
Trim$(Text1.Text) instead of Text1.Text directly... that way you protect
against the user accidentally entering a blank space into the TextBox.
Rick - MVP
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1514
by: trode | last post by:
It seems that if my WSDL source goes offline SOAPClient() creates un-trappable fatal errors. I don't think this is right. Shouldn't this be, at very least, trappable exceptions? This is the...
10
2287
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
0
2107
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
4
9823
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
24
5263
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
11
1655
by: Howard Kaikow | last post by:
I'm using the code below, but an error is not getting trapped. Where can such errors occur? In another process? Try SomeCode Catch ex As Exception Dim strMsg() As String = Split(ex.ToString,...
8
5566
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
1
12945
by: jared424oken | last post by:
we are geting an error Active Server Pages error 'ASP 0115' Unexpected error /catin.asp A trappable error (E06D7363) occurred in an external object. The script cannot continue running.
1
11438
by: santosh.anumandla | last post by:
Hi all, I am getting the following error randomly, I cannot expalin the exact scenario Active Server Pages error 'ASP 0115' Unexpected error /wmweb/Save.Asp A trappable error (C0000005)...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.