ajetrumpet
Banned
- Local time
- Today, 01:31
- Joined
- Jun 22, 2007
- Messages
- 5,638
Here is some code that will scramble a word or string using a dynamic array. In others words, scrambling or randomizing "on the fly" using functions...
Declarations:
Scramble Function:
Initialize Array:
You can scramble strings by calling both functions:
Declarations:
Code:
Public WrdArray() As String
Code:
Function Scramble(x As String, y As String)
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
ReDim Preserve WrdArray(UBound(WrdArray) + 1)
WrdArray(UBound(WrdArray)) = x & y
Else
For i = 1 To j
Call Scramble(x + Mid(y, i, 1), _
left(y, i - 1) + right(y, j - i))
Next i
End If
End Function
Code:
Function InitiateArray()
ReDim Preserve WrdArray(0)
End Function
Code:
Function ShowScrambledWord()
Randomize
Call InitializeArray
Call Scramble("", [COLOR="Red"]"STRING TO SCRAMBLE HERE")[/COLOR]
Debug.Print WrdArray(Int((UBound(WrdArray) - 0 + 1) * Rnd + 0))
End Function