Jay Holovacs help required!

R

riccifs

Hi Jay,
sorry if I'm writing to you but I have a question that I don't known
how to solve.

To handle names with mixed cases, on my form, I'm using the code you
wrote, I found it at this web-link: http://www.mvps.org/access/strings/str0008.htm
Of course, it works great and as I read it should be modular so that
it possible to add additional rules to handle special sequences of
characters.

What I'd like to do is to add in it a piece of code, to be able to
transform for example, string like that ''John spa'' in ''John
S.p.A.''
My trouble is that any time I write S.p.A., I do that hundred of
times, I have to remember to hit the point after each letters and at
same time I have to mind the case of the words.
It will be great if it doesn't matter how I to write ''spa'', the code
would change it in ''S.p.A.'' for me.
If you look the last part of the code you'll see a function to handle
roman number. If you write ''vii'' the code will change in ''VII'' for
you.
Could you think is possible to do something like that for my sequences
of words?
I'm not absolutely able to that, so I was thinking about you.

The words I'd like to be able to handle are: S.r.l. S.p.A. s.n.c.
s.a.s. S.r.l.u.

I hope you will be give to me an hand.....!
Thanks,
Stefano.
 
G

Guest

Stefano,

The easiest way would be to add the acronyms to the Autocorrect option of
the spell checker.

But, just for grins, try the modification below. Replace the current sub
"special_name" with the one below (or add the code between the ***'s)

'==========================
Private Sub special_name(str As String, ps As Integer)
'expects str to be a lower case string, ps to be the
'start of name to check, returns str modified in place
'modifies the internal character (not the initial)

Dim char2 As String
char2 = Mid$(str, ps, 2) 'check for Scots Mc
If (char2 = "mc") And Len(str) > ps + 1 Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

char2 = Mid$(str, ps, 2) 'check for ff
If (char2 = "ff") And Len(str) > ps + 1 Then 'ff form
Mid$(str, ps, 2) = LCase$(Mid$(str, ps, 2))
End If

char2 = Mid$(str, ps + 1, 1) 'check for apostrophe as 2nd char
If (char2 = "'") Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

Dim char3 As String
char3 = Mid$(str, ps, 3) 'check for scots Mac
If (char3 = "mac") And Len(str) > ps + 1 Then 'Mac form
Mid$(str, ps + 3) = UCase$(Mid$(str, ps + 3, 1))
End If

Dim char4 As String
char4 = Mid$(str, ps, 4) 'check for Fitz
If (char4 = "fitz") And Len(str) > ps + 1 Then 'Fitz form
Mid$(str, ps + 4) = UCase$(Mid$(str, ps + 4, 1))
End If

Dim char5 As String
char5 = Mid$(str, ps, 5) 'check for Fitz
If (char4 = "fitz") And Len(str) > ps + 1 Then 'Fitz form
Mid$(str, ps + 4) = UCase$(Mid$(str, ps + 4, 1))
End If

'****** check for special acronyms ******
Dim spChar As String
'strip periods
spChar = Replace(str, ".", "")

'check for S.r.l., S.p.A., s.n.c., s.a.s., S.r.l.u.
Select Case spChar
Case "srl"
str = "S.r.l. "
Case "srlu"
str = "S.r.l.u."
Case "spa"
str = "S.p.A."
Case "snc"
str = "s.n.c."
Case "sas"
str = "s.a.s."
End Select
'****** end check for special acronyms ******

End Sub
'==========================



HTH
 
R

riccifs

Stefano,

The easiest way would be to add the acronyms to the Autocorrect option of
the spell checker.

But, just for grins, try the modification below. Replace the current sub
"special_name" with the one below (or add the code between the ***'s)

'==========================
Private Sub special_name(str As String, ps As Integer)
'expects str to be a lower case string, ps to be the
'start of name to check, returns str modified in place
'modifies the internal character (not the initial)

Dim char2 As String
char2 = Mid$(str, ps, 2) 'check for Scots Mc
If (char2 = "mc") And Len(str) > ps + 1 Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

char2 = Mid$(str, ps, 2) 'check for ff
If (char2 = "ff") And Len(str) > ps + 1 Then 'ff form
Mid$(str, ps, 2) = LCase$(Mid$(str, ps, 2))
End If

char2 = Mid$(str, ps + 1, 1) 'check for apostrophe as 2nd char
If (char2 = "'") Then '3rd char is CAP
Mid$(str, ps + 2) = UCase$(Mid$(str, ps + 2, 1))
End If

Dim char3 As String
char3 = Mid$(str, ps, 3) 'check for scots Mac
If (char3 = "mac") And Len(str) > ps + 1 Then 'Mac form
Mid$(str, ps + 3) = UCase$(Mid$(str, ps + 3, 1))
End If

Dim char4 As String
char4 = Mid$(str, ps, 4) 'check for Fitz
If (char4 = "fitz") And Len(str) > ps + 1 Then 'Fitz form
Mid$(str, ps + 4) = UCase$(Mid$(str, ps + 4, 1))
End If

Dim char5 As String
char5 = Mid$(str, ps, 5) 'check for Fitz
If (char4 = "fitz") And Len(str) > ps + 1 Then 'Fitz form
Mid$(str, ps + 4) = UCase$(Mid$(str, ps + 4, 1))
End If

'****** check for special acronyms ******
Dim spChar As String
'strip periods
spChar = Replace(str, ".", "")

'check for S.r.l., S.p.A., s.n.c., s.a.s., S.r.l.u.
Select Case spChar
Case "srl"
str = "S.r.l. "
Case "srlu"
str = "S.r.l.u."
Case "spa"
str = "S.p.A."
Case "snc"
str = "s.n.c."
Case "sas"
str = "s.a.s."
End Select
'****** end check for special acronyms ******

End Sub
'==========================

HTH

Hi Steve,
many thanks for your answer, but I just solved using the regular
expressions.
I asked to my brother, his use to coding in pHp and he wrote a
function for me.
Regexp give to me great flexibility with text string and I can cover
any type any combinations....

Bye,
Stefano.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top