On Fri, 25 Jan 2008 12:11:01 +0700, "Chlaris"
OK. Try this:
Function ScrambleString(ByVal s As String) As String
'Scramble by putting characters in random order
Dim intPos As Integer
Dim i As Integer
Dim s2 As String
s2 = String(Len(s), 0) 'initially fill with ASCII 0
For i = 1 To Len(s)
intPos = 0
While intPos = 0
intPos = GetRandom(1, Len(s))
If Asc(Mid$(s2, intPos, 1)) = 0 Then
Mid$(s2, intPos, 1) = Mid$(s, i, 1)
Else
intPos = 0 'Signal that we want to try again. This
position already had a char.
End If
Wend
Next i
ScrambleString = s2
End Function
Private Function GetRandom(ByVal lowerbound As Integer, ByVal
upperbound As Integer) As Integer
GetRandom = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
End Function
In the Immediate window:
?ScrambleString("Hi There")
ihT reeH
heiHeTr
rTH ehei
h reTHei
-Tom.