Re: isnumeric compile error...



On Sun, 27 Jul 2008 21:31:35 -0700, Salad <oil@xxxxxxxxxxx> wrote:

Your first test I cannot confirm in A2007. If I have an unbound
textbox and an AfterUpdate event:
Private Sub Text47_AfterUpdate()
Debug.Print Text47.value, IsNumeric(Text47)
End Sub

Then it will consistently print:
1.1.1 False
Indeed IsNumeric works fine (no error) and since

I agree that an unbound textbox with value of 1.1.1 will run IsNumeric
just fine and it will return False. I agree we can think of this value
to be of type Variant, but if you test it using VarType, you will find
it is of type String.

I disagree when you say "If I am in Debug, to enter 1.1.1 not in
quotes is incorrect. Is isn't a number, it's a string"
I would argue: no it's not. It's an illegal value. Strings are wrapped
with "".

Isnumeric(Hi Tom!)
is also syntactically incorrect for the same reason.
Isnumeric("Hi Tom!")
is the correct syntax.

Assuming var is a Variant, there would not be an error, but just a
return value of False for var="1.1.1".

-Tom.



Tom van Stiphout wrote:
On Sun, 27 Jul 2008 19:50:17 -0700, Salad <oil@xxxxxxxxxxx> wrote:

Hi Salad,
I don't agree with your assertion "There's a difference between using
a form and entering data into an immedicate window" at least when it
comes to the performance of IsNumeric. Both environments use the same
VBA to do their job.

I can enter 1.1.1 into a text box with no quotes and IsNumeric works
just find.

If I am in Debug, to enter 1.1.1 not in quotes is incorrect. Is isn't a
number, it's a string. It's the same as if I wrote
? Isnumeric(Hi Tom!)
I'd expect an error.

I doubt MLH would have gotten an error if he did this
var = "1.1.1"
? Isnumeric(var)

The reason I would get an accurate result using an unbound textbox in a
form is that Text0, in my opionion, is similar to a variable of type
variant.


The reason isnumeric(1.2.2) fails whereas the other ones MLH mentions
succeed is that this one does not convert to a number or a string.
The help file says that IsNumeric takes a number or a string. 1.2.2 is
neither. That's why it fails.

The only time I can see MLH's error occurring is if he's doing
everything from the debug/immediate window. To me, that is a data
entry, perhaps logic, error he made in the Debug window. IOW...user error.

The advice he was seeking, as far as I'm concerned, is how does he/she
write statements in the Debug window and what to do if the statement is
incorrect.



-Tom.
Microsoft Access MVP




MLH wrote:

I have tested the following in immed window:

?isnumeric(1)
True
?isnumeric(1.)
True
?isnumeric(1.2)
True
?isnumeric(1.2.2)

The last one does not print True nor False.
Instead, A97 complains of a compile error.
I would really prefer False, should such be
the case. What's the best way not to be
bothered with the error and just assume
False is returned?

Experimenting with CStr was not fruitful
because 1.2.2 is neither a valid numeric
expression nor a valid string expression.

Why is it not a valid string?


So, what can I do if I find myself needing
to process ?CStr(1.2.2) in the same way
?CStr("1.2.2") would be processed.

Put quotes around it. You're in debug, not a form or report or query or
table.


If a user enters 1.2.2 in an unbound text-
box expecting a valid numeric entry, I
would like very much to determine, in
code, that it is NOT a valid numeric.
But IsNumeric(1.2.2) is not the answer
and neither is IsNumeric(CStr(1.2.2)). So
what do I do?

I created a form. I added a textbox. In the AfterUpdate event I have
the following code.
Private Sub Text2_AfterUpdate()
If IsNumeric(Me.Text2) Then
MsgBox "Numeric"
Else
MsgBox "Alpha"
End If
End Sub

I entered 1.2.2 and I got "Alpha". Which is correct.

There's a difference between using a form and entering data into an
immedicate window.
.



Relevant Pages

  • Re: Combo box woes
    ... which when clicked makes my textbox visible ... > will enter a string that is the search string. ... and a listbox (name it lstNames) in that section. ... > Private Sub txtString_AfterUpdate ...
    (microsoft.public.access.forms)
  • Re: Challenge: selective parse of strings
    ... Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ... > I am trying to get it so that if the user enters a word in textbox1> that is not in the dictionary, then a message comes up "word not in> dictionary" and then the word is parsed into individual letters and> placed back into the textbox as the person types. ... The code seems to trigger whenever any> two sub-strings are joined together It needs to check for the> string using the " " delimiter. ... > Dim str() As String, ...
    (microsoft.public.excel.programming)
  • Re: Date validation not working
    ... Show examples of what you're typing into the textbox ... >>>> this is a text string, not a date, in ACCESS terms. ... >>>> could use a validation rule similar to this: ... >>>> Private Sub DateTextBoxName_BeforeUpdate ...
    (microsoft.public.access.formscoding)
  • Re: Combo box woes
    ... > I've included the Find button, which when clicked makes my textbox visible ... >> will enter a string that is the search string. ... and a listbox (name it lstNames) in that section. ... >> Private Sub txtString_AfterUpdate ...
    (microsoft.public.access.forms)
  • RE: Open a form with a filter based on dependent data
    ... and I am prompted in a window called "Enter parameter ... data_entry's primary key is known as "ID", and has a bunch of other fields. ... Private Sub Command200_Click'This is the relations button ... Dim holdval As String ...
    (microsoft.public.access.forms)