Click here to Skip to main content
15,886,919 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Why? Just why? Pin
Kornfeld Eliyahu Peter25-Mar-14 0:03
professionalKornfeld Eliyahu Peter25-Mar-14 0:03 
GeneralRe: Why? Just why? Pin
Nagy Vilmos25-Mar-14 0:33
professionalNagy Vilmos25-Mar-14 0:33 
GeneralRe: Why? Just why? Pin
Argonia25-Mar-14 1:29
professionalArgonia25-Mar-14 1:29 
GeneralRe: Why? Just why? Pin
Rob Grainger31-Mar-14 2:06
Rob Grainger31-Mar-14 2:06 
GeneralRe: Why? Just why? Pin
Fueled By Decaff1-Apr-14 2:08
Fueled By Decaff1-Apr-14 2:08 
GeneralRe: Why? Just why? Pin
Chris Quinn25-Mar-14 1:44
Chris Quinn25-Mar-14 1:44 
GeneralRe: Why? Just why? Pin
Nagy Vilmos25-Mar-14 2:13
professionalNagy Vilmos25-Mar-14 2:13 
GeneralRe: Why? Just why? Pin
Chris Quinn25-Mar-14 4:31
Chris Quinn25-Mar-14 4:31 
Here's my monkey giblets! I knew I still had it somewhere

VB
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
    'Lowercase the whole string

    StringLength = Len(Sourcestring)
    Sourcestring = LCase$(Sourcestring)

    For loopvar = 1 To StringLength
        'loop through the string letter by letter and
        'Convert the letter to uppercase if it is :-

        'The First Character in the text box
        ConvertChar = (loopvar = 1)

        'or character following space, hypen or apostrophe
        If Not ConvertChar Then ConvertChar = InStr(" -' ", Mid$(Sourcestring, (loopvar - 1), 1))

        ''or first character following a Mc for the Scots amongst us
        '    If Not ConvertChar Then
        '        If loopvar > 2 Then ConvertChar = (Mid$(SourceString, (loopvar - 2), 2) = "mc")
        '    End If

        Nextchar = Mid$(Sourcestring, loopvar, 1)
        If ConvertChar Then        'Convert character to uppercase if it meets the criteria
            Nextchar = UCase$(Nextchar)
        End If
        Newstring = Newstring & Nextchar        'Concatenate to destination
    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        'return the completed string

ExitHere:
    Exit Function

    ' Error handling block added by Error Handler Add-In. DO NOT EDIT this block of code.
    ' Automatic error handler last updated at 09-21-2004 10:35:07   'ErrorHandler:$$D=09-21-2004    'ErrorHandler:$$T=10:35:07
HandleErr:
    Select Case Err.Number
        Case Else
            MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "modFunctions.Namecase"        'ErrorHandler:$$N=modFunctions.Namecase
    End Select
    ' End Error handling block.
End Function

=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================

GeneralRe: Why? Just why? Pin
Jörgen Andersson25-Mar-14 5:00
professionalJörgen Andersson25-Mar-14 5:00 
GeneralRe: Why? Just why? Pin
Nagy Vilmos25-Mar-14 6:24
professionalNagy Vilmos25-Mar-14 6:24 
GeneralRe: Why? Just why? Pin
Jörgen Andersson25-Mar-14 9:30
professionalJörgen Andersson25-Mar-14 9:30 
GeneralRe: Why? Just why? Pin
BobJanova25-Mar-14 6:28
BobJanova25-Mar-14 6:28 
GeneralRe: Why? Just why? Pin
Nagy Vilmos25-Mar-14 6:48
professionalNagy Vilmos25-Mar-14 6:48 
GeneralRe: Why? Just why? Pin
Chris Quinn25-Mar-14 22:00
Chris Quinn25-Mar-14 22:00 
GeneralRe: Why? Just why? Pin
MarkTJohnson26-Mar-14 6:53
professionalMarkTJohnson26-Mar-14 6:53 
GeneralRe: Why? Just why? Pin
Bernhard Hiller25-Mar-14 21:49
Bernhard Hiller25-Mar-14 21:49 
GeneralRe: Why? Just why? PinPopular
Dave Kreskowiak26-Mar-14 4:29
mveDave Kreskowiak26-Mar-14 4:29 
GeneralRe: Why? Just why? Pin
Nagy Vilmos26-Mar-14 4:45
professionalNagy Vilmos26-Mar-14 4:45 
GeneralRe: Why? Just why? Pin
BobJanova26-Mar-14 4:52
BobJanova26-Mar-14 4:52 
GeneralRe: Why? Just why? Pin
ZurdoDev26-Mar-14 5:11
professionalZurdoDev26-Mar-14 5:11 
GeneralRe: Why? Just why? Pin
Chris Quinn26-Mar-14 5:46
Chris Quinn26-Mar-14 5:46 
GeneralRe: Why? Just why? Pin
Brisingr Aerowing30-Mar-14 7:10
professionalBrisingr Aerowing30-Mar-14 7:10 
GeneralRe: Why? Just why? Pin
Rob Grainger31-Mar-14 2:10
Rob Grainger31-Mar-14 2:10 
GeneralRe: Why? Just why? Pin
mikepwilson28-Mar-14 3:13
mikepwilson28-Mar-14 3:13 
GeneralRe: Why? Just why? Pin
Nagy Vilmos28-Mar-14 3:20
professionalNagy Vilmos28-Mar-14 3:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.