From: Jon Lewis on
I rarely use the Like operator and below is the only way I could get a
function to return true if
str is all numbers or all numbers followed by a single letter

Is there an easier way?

TIA

Jon

Private Function IsPrefix(str As String) As Boolean
'Is str all numbers or all numbers followed by a single letter
If Right(str, 1) Like "[a-z]" Then
If Not Left(str, Len(str) - 1) Like "*[!0-9]*" Then
IsPrefix = True
Else
IsPrefix = False
End If
ElseIf Not str Like "*[!0-9]*" Then
IsPrefix = True
Else
IsPrefix = False
End If
End Function


From: Salad on
Jon Lewis wrote:

> I rarely use the Like operator and below is the only way I could get a
> function to return true if
> str is all numbers or all numbers followed by a single letter
>
> Is there an easier way?
>
> TIA
>
> Jon
>
> Private Function IsPrefix(str As String) As Boolean
> 'Is str all numbers or all numbers followed by a single letter
> If Right(str, 1) Like "[a-z]" Then
> If Not Left(str, Len(str) - 1) Like "*[!0-9]*" Then
> IsPrefix = True
> Else
> IsPrefix = False
> End If
> ElseIf Not str Like "*[!0-9]*" Then
> IsPrefix = True
> Else
> IsPrefix = False
> End If
> End Function
>
>
Don't know if its easier
X= "12345A"
? IsNumeric(Left(x,len(x)-1)) And Isnumeric(x)
False
X= "12345"
? IsNumeric(Left(x,len(x)-1)) And Isnumeric(x)
True
From: Marshall Barton on
Jon Lewis wrote:

>I rarely use the Like operator and below is the only way I could get a
>function to return true if
>str is all numbers or all numbers followed by a single letter
>
>Is there an easier way?
>
>TIA
>
>Jon
>
>Private Function IsPrefix(str As String) As Boolean
>'Is str all numbers or all numbers followed by a single letter
> If Right(str, 1) Like "[a-z]" Then
> If Not Left(str, Len(str) - 1) Like "*[!0-9]*" Then
> IsPrefix = True
> Else
> IsPrefix = False
> End If
> ElseIf Not str Like "*[!0-9]*" Then
> IsPrefix = True
> Else
> IsPrefix = False
> End If
>End Function
>

That's how I would do it. AFAIK, it's the only reliable way
short of looping through each character.

--
Marsh
From: Jon Lewis on
OK Thanks Marshall

Jon

"Marshall Barton" <marshbarton(a)wowway.com> wrote in message
news:9qdc4614sa0p3kimrqeh0rfrlkf424j71k(a)4ax.com...
> Jon Lewis wrote:
>
>>I rarely use the Like operator and below is the only way I could get a
>>function to return true if
>>str is all numbers or all numbers followed by a single letter
>>
>>Is there an easier way?
>>
>>TIA
>>
>>Jon
>>
>>Private Function IsPrefix(str As String) As Boolean
>>'Is str all numbers or all numbers followed by a single letter
>> If Right(str, 1) Like "[a-z]" Then
>> If Not Left(str, Len(str) - 1) Like "*[!0-9]*" Then
>> IsPrefix = True
>> Else
>> IsPrefix = False
>> End If
>> ElseIf Not str Like "*[!0-9]*" Then
>> IsPrefix = True
>> Else
>> IsPrefix = False
>> End If
>>End Function
>>
>
> That's how I would do it. AFAIK, it's the only reliable way
> short of looping through each character.
>
> --
> Marsh


From: David Kaye on
"Jon Lewis" <jon.lewis(a)cutthespambtinternet.com> wrote:
>I rarely use the Like operator and below is the only way I could get a
>function to return true if
>str is all numbers or all numbers followed by a single letter
>
>Is there an easier way?

I'm assuming you mean that 12345A is true and 12345 is true but A12345 if
false and A is false.

If that's the case I'd probably do:

select case val(str$)
case 10000 to 99999
maybeok=true
case else
maybeok=false
end select
select case right$(str$,1)
case "A" to "Z", "a" to "z"
if maybeok then
isokay=true
else
isokay=false
end if
case else
isokay=false
end select

 |  Next  |  Last
Pages: 1 2 3
Prev: formatting
Next: A2010 question regarding web app