max.wanadoo at gmail.com
max.wanadoo at gmail.com
Mon Oct 1 07:47:01 CDT 2007
Thanks Gustav,missed those bits.
Poking now completes in 3 min 26 sec
Concatenating now completes in 3 mins 41 seconds
A diff of 14 secs over 1 million iterations.
Max
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock
Sent: Monday, October 01, 2007 1:11 PM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Use Regex - Create Camel Case
Hi Max
No, they are not identical. Here is the corrected version which now runs
slightly faster:
Function CamelCaseBestSoFar4VBAPoking()
' ' This times at 4 mins 16 seconds
' This times at 3 mins 40 seconds
Dim tStartTime As Date, tEndTime As Date, tLapsedTime As Date, iLoop As
Long, iVarLoop As Integer
Dim iLenLoop As Integer, iVars As Integer
Dim bFlipCase As Boolean, str2Parse As String, strResult As String, strBit
As String
Dim varStr(5), lngPos As Long
varStr(1) = "John colby " ' Result wanted: "JohnColby"
varStr(2) = "%idiotic_Field*name&!@" ' Result wanted: "IdioticFieldName"
varStr(3) = " # hey#hey#Hey,hello_world$%#" ' Result wanted:
"HeyHeyHeyHelloWorld"
varStr(4) = "@#$this#is_a_test_of_the-emerGency-broadcast-system" ' Result
wanted: "ThisIsATestOftheEmergencyBroadcastSystem"
varStr(5) = "thisisastringwithnobadchars" ' Result wanted:
"Thisisastringwithnobadchars"
iVars = 5
tStartTime = Now
For iLoop = 1 To conIterations
For iVarLoop = 1 To iVars
' str2Parse = varStr(iVarLoop): bFlipCase = True: strResult =
Left(Space(255), Len(str2Parse)): lngPos = 0
str2Parse = LCase(varStr(iVarLoop)): bFlipCase = True: strResult =
Space(Len(str2Parse)): lngPos = 0
For iLenLoop = 1 To Len(str2Parse)
' strBit = LCase(Mid(str2Parse, iLenLoop, 1))
strBit = Mid(str2Parse, iLenLoop, 1)
If InStr(conBadChars, strBit) = 0 Then
lngPos = lngPos + 1
If bFlipCase = True Then strBit = UCase(strBit): bFlipCase = False
Mid(strResult, lngPos, 1) = strBit
Else
bFlipCase = True
End If
Next iLenLoop
strResult = Trim(strResult) ' drop any spaces left in string
'Debug.Print strResult
Next iVarLoop
Next iLoop
tEndTime = Now
tLapsedTime = tEndTime - tStartTime
'MsgBox tLapsedTime:
Debug.Print tLapsedTime
End Function
/gustav