Solved

function to see if a word has a number in it

Posted on 2014-09-13
9
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 47

Expert Comment

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

Author Comment

by:PeterBaileyUk
ID: 40320966
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
ID: 40320967
hence need of a function
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 167 total points
ID: 40320996
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
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 166 total points
ID: 40321003
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40321008
Dale,
better read the codes I posted carefully..
0
 
LVL 47

Expert Comment

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

Still, way more cumbersome than a simple Like comparison.

Dale
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 167 total points
ID: 40321162
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
ID: 40321474
ok guys i have shared the points hope that remains acceptable.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

696 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