Word Scrambler (1 Viewer)

Status
Not open for further replies.

ajetrumpet

Banned
Local time
Today, 02:36
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:
Code:
Public WrdArray() As String
Scramble Function:
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
Initialize Array:
Code:
Function InitiateArray()

    ReDim Preserve WrdArray(0)

End Function
You can scramble strings by calling both functions:
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
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom