From: Jon Lewis on 20 Jul 2010 11:03 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 20 Jul 2010 11:44 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 20 Jul 2010 19:59 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 21 Jul 2010 07:14 OK Thanks Marshall Jon "Marshall Barton" 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 21 Jul 2010 17:25 "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? 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: formattingNext: A2010 question regarding web app