Solved

test for inclusion or removal of hyphen or other gramatical character

Posted on 2011-03-22
5
302 Views
Last Modified: 2012-05-11
I would like a function to pick up if a string has only a minor change:

strcurrent: HI-LUX
strprevious: HILUX

strprevious:HI-LUX LE D/CAB D-4D 4X4 170
strcurrent::HILUX LE D/CAB D-4D 4X4 170

In these examples the function would return false ie no difference
if it could allow for / -

essentially if after removal or inclusion of the characters it matches the original string then there is no difference whereas additional text does make a difference.
I am working in access 2010 vba

0
Comment
Question by:PeterBaileyUk
  • 3
5 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
ID: 35188558
Superficially simple but with the potential for becoming a project on its own.

This is the simple  and NOT comprehensive solution..

It compares two strings, each pass of the loop replaces a the next 'unrequired' character with a designated replacement character (space in this version) and then compares the result.
If at any time the revised strings match the function returns a True value.  Otherwise it reurns False.

Function sameafterremchars(ByVal str1, ByVal str2) As Boolean
Dim remlist As String
Dim curchar As String
Dim x As Long, y As Long
Dim replacewith As String

sameafterremchars = True  ' default is strings are the same
If str1 = str2 Then Exit Function   ' no further tests required
remlist = "-*@"    ' list of characters to be replaced
replacewith = " "   ' replace unwanted characters with this character
y = Len(remlist)
For x = 1 To y
curchar = Mid(remlist, x, 1)
str1 = Replace(str1, curchar, replacewith)
str2 = Replace(str2, curchar, replacewith)
If str1 = str2 Then Exit Function
Next x
' strings not equal if code gets here
sameafterremchars = False
End Function


However, I think you will find this is the thin end of the wedge.  Once you start on this route you will never come to an end. as there will always be another character to test for or another variation which conflicts with an earlier test.

You are heading into 'google search' terrritory (fuzzy matching) and even google doesn't get that right.


0
 

Author Comment

by:PeterBaileyUk
ID: 35188591
understandable I think if i can capture most it will be ok so that the remainder is a word change or addition. On the main part its also experimental if it ( a technique) works great if not then i know i tried.

:)


0
 
LVL 19

Assisted Solution

by:darbid73
darbid73 earned 250 total points
ID: 35188696
I looked at your question and also thought it was in need of a real solution that would take too long to do.

Given peter57r's response I will give you my thoughts in a non-coded way.  But I too think if you go down this track you will be there for a long time.

I was thinking that you could use the following which determines if the character is a letter of the alphabet or not.

Private Function AllLetters(ByVal txt As String) As Boolean
Dim ch As String
Dim i As Integer

    AllLetters = True
    txt = UCase$(txt)
    For i = 1 To Len(txt)
        ' See if the next character is a non-digit.
        ch = Mid$(txt, i, 1)
        If ch < "A" Or ch > "Z" Then
            ' This is not a letter.
            AllLetters = False
            Exit For
        End If
    Next i
End Function

The idea being that you use the MID function to get character no. 1 from both strings and compare this character.  If they are the same you move to the next character.  If they are different and NOT a letter of the alphabet then raise an error or add it to the problem list.
0
 

Author Comment

by:PeterBaileyUk
ID: 35191711
I wonder if its better doing the evaluation word by word:

if the number of words has decreased or increased then flag for attention

if word count the same then

compare each word if the word matches then ignore it until i am down to whats left in the following ex

strprevious:HI-LUX LE D/CAB D-4D 4X4 170
strcurrent::HILUX LE D/CAB D-4D 4X4 170

resolves down to
HI-LUX
HILUX

here i could remove the hyphen and compare if true do nothing however if false then flag.



0
 

Author Closing Comment

by:PeterBaileyUk
ID: 35192145
I have awarded the points anyway despite writing the solution as without your ideas I would not have got there!

thank u both.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

825 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