We help IT Professionals succeed at work.
Get Started

amend function in vba

PeterBaileyUk
on
365 Views
Last Modified: 2014-06-07
I have this function but it needs a slight amendment.

It fails on these strings:

strcurin= "a3 110"
strtestfieldin=a3

cur in=A3 S LINE BLACK EDITION (138)
testfield=A3 S LINE BLACK EDITION

each of the five words appears in cur

this one will fail

cur=A3 S LINE BLACK EDITION QUATTRO (170
testfield=A3 S LINE BLACK EDITION QUATTRO (

the first 6 words are in but the seventh word"(" is not a word in cur, it is a substring of (170" but i dont want that comparison.


it should pass as a3 in test field is a word in curin

I remmed out the piece that tests elements on both sides are there as the strtestfieldin could have or be equal too the elements of strcurin.

so cur will never be less than the test string

here i want to test if a3 exists as a word in strtestfieldin but not as an instring word for word.

the test fields are having things extracted from them. the remaining words should appear in cur somewhere, unless an extraction routine left a part word.

Function word4wordCheck(StrCURIn As String, StrTESTFieldin As String) As Boolean

'    Dim ExtractWordsPhrase1() As String
'    Dim ExtractWordsPhrase2() As String
'    Dim WordCountPhrase1, WordCountPhrase2 As Integer
'    Dim intLoop As Integer
'
'    ExtractWordsPhrase1 = Split(Trim(StrCURIn), " ")
'    ExtractWordsPhrase2 = Split(Trim(StrTESTFieldin), " ")
'
''    'If element count of arrays differ return false
''    If UBound(ExtractWordsPhrase1) <> UBound(ExtractWordsPhrase2) Then
''        word4wordCheck = False
''        Exit Function
''    End If
'
'    'Check each element of Array
'    For intLoop = LBound(ExtractWordsPhrase1) To UBound(ExtractWordsPhrase1)
'        If ExtractWordsPhrase1(intLoop) <> ExtractWordsPhrase2(intLoop) Then
'            word4wordCheck = False
'            Exit Function
'        End If
'    Next
'
'    word4wordCheck = True

End Function

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE