|
Just another way of saying, "WTF am I doing?"
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
I know, lets keep re-comparing strings as it's cheap and easy. Thank you VB6; the gift that keeps on giving.
Public Function sConvertCase(sInString, lType As VbStrConv) As String
Dim sReturn As String
Dim lPos As Long
Dim lStart As Long
Dim lNext As Long
On Local Error Resume Next
sReturn = StrConv(sInString, lType)
If lType = vbProperCase Then
lPos = 0
Do
lStart = lPos + 1
lPos = InStr(lStart, sReturn, "Mc")
lNext = InStr(lStart, sReturn, "Mac")
If lNext > 0 And (lNext < lPos Or lPos = 0) Then
lPos = lNext
End If
lNext = InStr(lStart, sReturn, "O'")
If lNext > 0 And (lNext < lPos Or lPos = 0) Then
lPos = lNext
End If
lNext = InStr(lStart, sReturn, "Von ")
If lNext > 0 And (lNext < lPos Or lPos = 0) Then
lPos = lNext
End If
lNext = InStr(lStart, sReturn, "-")
If lNext > 0 And lNext < lPos Or lPos = 0 Then
lPos = lNext
End If
If lPos = 0 Then
ElseIf Mid$(sReturn, lPos, 1) = "-" Then
Mid$(sReturn, lPos + 1, 1) = UCase$(Mid$(sReturn, lPos + 1, 1))
ElseIf Mid$(sReturn, lPos, 2) = "Mc" Then
Mid$(sReturn, lPos + 2, 1) = UCase$(Mid$(sReturn, lPos + 2, 1))
ElseIf Mid$(sReturn, lPos, 3) = "Mac" Then
If Mid$(sInString, lPos, 3) = "Mac" And Mid$(sInString, lPos + 3, 1) = UCase$(Mid$(sInString, lPos, 3)) Then
Mid$(sReturn, lPos + 3, 1) = UCase$(Mid$(sReturn, lPos + 3, 1))
End If
ElseIf Mid$(sReturn, lPos, 2) = "O'" Then
Mid$(sReturn, lPos + 2, 1) = UCase$(Mid$(sReturn, lPos + 2, 2))
ElseIf Mid$(sReturn, lPos, 4) = "Von " Then
Mid$(sReturn, lPos, 1) = "v"
End If
Loop While lPos > 0
End If
Done:
sConvertCase = sReturn
End Function
|
|
|
|
|
I can't see how it's connected to VB6 (or any language for that matter)...It's a pure human problem...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
No, I think on reflection I will continue to blame VB6. On the plus side, the code so far is not dead awful but it is visibly aged in the approach. No refactoring yet, I've agreed that we'll get it working with as little changes as possible [he laughs] and then look at more robust approaches.
|
|
|
|
|
Nagy Vilmos wrote: robust approaches Like Format : ?
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
Actually string handling in VB6 is particularly dire. The "natural" syntax encourages you to build strings from smaller ones, but the implementation just reallocates.
I remember seeing some code building particularly long strings that had exponentially increasing performance time on long input - entirely due to naive string-handling.
There are workarounds, but the language has to take some blame here.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Erm, isn't it the same as natural string handling in C#?
Yes, I do know you should use a StringBuilder, but a new coder would not necessarily know that.
|
|
|
|
|
I wrote a very similar routine for Access many years ago, but it's better as it handles special cases like 'Macari' and 'Macy' which this routine would render as 'MacAri ' and 'MacY'
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
It still sucks monkey giblets
|
|
|
|
|
Here's my monkey giblets! I knew I still had it somewhere
Function Namecase(ByVal Sourcestring As String) As String
Dim ConvertChar As Integer, Jock As Integer
Dim StringLength As Integer, loopvar As Integer
Dim Newstring As String, Nextchar As String
Dim MacPos As Integer, Maclen As Integer, TestMac As String
On Error GoTo HandleErr
StringLength = Len(Sourcestring)
Sourcestring = LCase$(Sourcestring)
For loopvar = 1 To StringLength
ConvertChar = (loopvar = 1)
If Not ConvertChar Then ConvertChar = InStr(" -' ", Mid$(Sourcestring, (loopvar - 1), 1))
Nextchar = Mid$(Sourcestring, loopvar, 1)
If ConvertChar Then
Nextchar = UCase$(Nextchar)
End If
Newstring = Newstring & Nextchar
Next loopvar
TestMac = "|" & Newstring & "|"
MacPos = (InStr("|Machin|Macaskill|Mack|Mackie|Macaly|Macy|Mace|Macari|Macley|Macnamara|Mackay|", TestMac))
Jock = (MacPos = 0)
If Jock Then
MacPos = InStr(Newstring, "Mac")
Maclen = Len(Newstring)
If MacPos > 0 Then
Newstring = left$(Newstring, MacPos + 2) & (UCase$(Mid$(Newstring, MacPos + 3, 1)) & right$(Newstring, (Maclen - (MacPos + 3))))
End If
MacPos = InStr(Newstring, "Mc")
If MacPos > 0 Then
Newstring = left$(Newstring, MacPos + 1) & (UCase$(Mid$(Newstring, MacPos + 2, 1)) & right$(Newstring, (Maclen - (MacPos + 2))))
End If
End If
Namecase = Newstring
ExitHere:
Exit Function
HandleErr:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "modFunctions.Namecase"
End Select
End Function
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
How about McHammer?
|
|
|
|
|
|
I'm Too Legit to Quit, I Don't Stop until I'm Gaining Momentum. So Feel My Power it's Hammertime.
|
|
|
|
|
MacAskill and (definitely) MacNamara look like they are real Macs.
This kind of code just implies your input and/or requirements are crap, though. People should be trusted to type their own name as they want it.
|
|
|
|
|
This goes back to a more elegant age where people couldn't use puters.
|
|
|
|
|
I have a Scottish friend called Macaskill who definitely does not capitalise internally, and the others were ascertained by looking through the telephone directories of several major British cities, though I think Macnamara[^] is a special special case - some capitalise and some don't
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Glad to see it takes care of MacHine
|
|
|
|
|
Well, you have to run that code at the speed of MacH 2.
|
|
|
|
|
You thought that code was bad??
How about this[^] little gem, written in C#??
I hate hearing crap about VB being the sole domain of horrible code.
|
|
|
|
|
|
|
I'm surprised that CP didn't give an "Out of memory exception" when the OP posted that code. Whew!
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
As I always say, it ain't the tool that is used that's the problem, but the tool that uses it.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
What do you get when you cross a joke with a rhetorical question?
|
|
|
|
|
Not the sole domain, but a particularly frequent one due to some bad language design decisions.
JavaScript is similarly plagued, and of course one can always create bad code in any language, just some make it the default way of working for many.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|