From: LondonLad on
Hi
xStr can contain a string which includes numbers or not contain numbers

if it contains numbers I want to edit it.

In my example which does not work
xStr = "03 Best of Time"

If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text = "No"

Can you help please

Ron
From: Rick Rothstein on
The Like operator can help out here...

If xStr Like "*#*" Then
' xStr contains one or more digits
Else
' All characters in xStr are non-digits
End If

--
Rick (MVP - Excel)



"LondonLad" <LondonLad(a)discussions.microsoft.com> wrote in message
news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com...
> Hi
> xStr can contain a string which includes numbers or not contain numbers
>
> if it contains numbers I want to edit it.
>
> In my example which does not work
> xStr = "03 Best of Time"
>
> If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text = "No"
>
> Can you help please
>
> Ron

From: Helmut Meukel on
"LondonLad" <LondonLad(a)discussions.microsoft.com> schrieb im Newsbeitrag
news:B96BED25-0A88-4124-9E61-3B874330B57D(a)microsoft.com...
> Hi
> xStr can contain a string which includes numbers or not contain numbers
>
> if it contains numbers I want to edit it.
>
> In my example which does not work
> xStr = "03 Best of Time"
>
> If IsNumeric(xStr) Then txtHold.Text = "Yes" Else txtHold.Text = "No"
>
> Can you help please
>
> Ron



Ron,

depending on where the number(s) are, Val(xStr) may work.

The ancient Val function returns a Double if the string starts with
a number. It stops conversion when it encounters a non-numerical
character. If the string starts with a non-numerical character it
will return 0. It's not localized, it recognizes only the dot as
decimal sign.
Spaces are totally ignored by Val.

Here some examples:
Val("123 that's for me") will return 123 but
Val("1, 2, 3, that's for me") will return 1, because there is a
comma after the 1.
Val(".25 $") will return 0.25
Val("$ 125") will return 0, because the string starts with a
non-numerical character
Val("5 6 7 8") will return 5678
Val("- 12" will return -12

If you are certain about how your data looks like,
and you want speed, Val may be your choice.

Helmut.


From: Jim Mack on
Helmut Meukel wrote:
>
> depending on where the number(s) are, Val(xStr) may work.
>
> Here some examples:
> Val("123 that's for me") will return 123 but
> Val("1, 2, 3, that's for me") will return 1, because there is a
> comma after the 1.
> Val(".25 $") will return 0.25
> Val("$ 125") will return 0, because the string starts with a
> non-numerical character
> Val("5 6 7 8") will return 5678
> Val("- 12" will return -12
>
> If you are certain about how your data looks like,
> and you want speed, Val may be your choice.

Before relying on it, try one like this:

? Val("123 E 45th Ave")

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

From: Helmut Meukel on
"Jim Mack" <jmack(a)mdxi.nospam.com> schrieb im Newsbeitrag
news:%23E632OJ7KHA.5644(a)TK2MSFTNGP04.phx.gbl...
> Helmut Meukel wrote:
>>
>> depending on where the number(s) are, Val(xStr) may work.
>>
>> Here some examples:
>> Val("123 that's for me") will return 123 but
>> Val("1, 2, 3, that's for me") will return 1, because there is a
>> comma after the 1.
>> Val(".25 $") will return 0.25
>> Val("$ 125") will return 0, because the string starts with a
>> non-numerical character
>> Val("5 6 7 8") will return 5678
>> Val("- 12" will return -12
>>
>> If you are certain about how your data looks like,
>> and you want speed, Val may be your choice.
>
> Before relying on it, try one like this:
>
> ? Val("123 E 45th Ave")
>
> --
> Jim Mack
> Twisted tees at http://www.cafepress.com/2050inc
> "We sew confusion"
>


That's a fine example how Val can misinterpret the number <g>
One E or one D within a Number is interpreted as scientific
notation.
As I said, "if you are certain about the look of your data ..."
I just forgot to add "and know about the quirks of Val".

Helmut.