Solved

function to see if a word has a number in it

Posted on 2014-09-13
9
169 Views
Last Modified: 2014-09-14
I need to see if a word has any numerals in it:

"String!"= false
"string12" = true
"1245" =true
"1245six"=true
"str13str"=true

not sure how to do that part

I can grab the strings and split them and put them into an array

not sure how to achieve the function.
am in vba
0
Comment
Question by:PeterBaileyUk
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
? (" " & "asd1" & " ") like "*[1-9]*"
0
 

Author Comment

by:PeterBaileyUk
Comment Utility
i need to test within a for loop in vba

for the second word in the wordarray(index)

check if word has numerals
if yes out true

next wordarray
0
 

Author Comment

by:PeterBaileyUk
Comment Utility
hence need of a function
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 167 total points
Comment Utility
dim j as integer
for j=1 to len(wordarray(index))
      if isnumeric(mid(wordarray(index),j,1)) then
         numberexists=true
         exit for
      end if
next
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 166 total points
Comment Utility
Rey,

he didn't say he wanted to know whether it isNumeric() the OP stated "I need to see if a word has any numerals in it", with examples of:

"String!"= false
"string12" = true

Peter, since you done describe the for loop criteria, here is an example

For intloop = 1 to intSomething

   If WordArray(1) LIKE "*[0-9]*" Then
       'do something here
   Endif

Next
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
Dale,
better read the codes I posted carefully..
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
My bad, thought you were looping through his array.

Still, way more cumbersome than a simple Like comparison.

Dale
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 167 total points
Comment Utility
Or you can use regular expressions:
Sub Demo()
    Dim strArray() As String
    Dim i As Integer

    strArray = Split("String! string12 1245 1245six str13str", " ")

    For i = LBound(strArray) To UBound(strArray)
        If fContainsNumerals(strArray(i)) Then
            MsgBox "Array element " & i & ": " & strArray(i) & " contains numerals!"
        Else
            MsgBox "Array element " & i & ": " & strArray(i) & " doesn't contains numerals!"
        End If
    Next
End Sub

Function fContainsNumerals(ByVal strInput As String) As Variant

    With CreateObject("VbScript.RegExp")
        .Global = True
        .Pattern = "[^\D]"
        fContainsNumerals = .test(strInput)
    End With

End Function

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
Comment Utility
ok guys i have shared the points hope that remains acceptable.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now