-
Scramble Text
Here is what I ahve
Code:
Function ScrambleText(Thetext As String)
'sees if there's a space in the text to
' be scrambled,
'if found space, continues, if not, adds
' it
findlastspace = Mid(Thetext, Len(Thetext), 1)
If Not findlastspace = " " Then
Thetext = Thetext & " "
Else
Thetext = Thetext
End If
'Scrambles the text
For scrambling = 1 To Len(Thetext)
thechar$ = Mid(Thetext, scrambling, 1)
Char$ = Char$ & thechar$
If thechar$ = " " Then
'takes out " " space from the text left
' of the space
chars$ = Mid(Char$, 1, Len(Char$) - 1)
'gets first character
firstchar$ = Mid(chars$, 1, 1)
'gets last character (if not, makes firs
' t character only)
On Error GoTo cityz
lastchar$ = Mid(chars$, Len(chars$), 1)
'finds what is inbetween the last and fi
' rst character
midchar$ = Mid(chars$, 2, Len(chars$) - 2)
'reverses the text found in between the
' last and first
'character
For SpeedBack = Len(midchar$) To 1 Step -1
backchar$ = backchar$ & Mid$(midchar$, SpeedBack, 1)
Next SpeedBack
GoTo sniffe
'adds the scrambled text to the full scr
' ambled element
cityz:
scrambled$ = scrambled$ & firstchar$ & " "
GoTo sniffs
sniffe:
scrambled$ = scrambled$ & lastchar$ & firstchar$ & backchar$ & " "
'clears character and reversed buffers
sniffs:
Char$ = ""
backchar$ = ""
End If
Next scrambling
'Makes function return value the scrambl
' ed text
ScrambleText = scrambled$
End Function
usage i tried real quick
ScrambleText(Text1.Text)
it keeps saying compile error and highlighting this line
Code:
findlastspace = Mid(Thetext, Len(Thetext), 1)
it highlights findlastspace
-
what is the compile error? Are you using Option Explicit? If so, findlastspace is not declared
:)
-
thats exactly what i'm getting...i get that all the time..how do i define it?
-
It looks like you should declare it as a string
-
-
ya that worked..but i can't figure out the usage...it keeps saying argument not optional
-
-
no the way i'm using it is getting highlighted like
ScrambleText (Text1.Text)
its highlighting ScrambleText..almost like i'm spelling it wrong or something
-
even if i do
Private Sub Command2_Click()
ScrambleText
End Sub
it highlights it and says argument not optional..***
-
well, the function should explicitly return a string, which it doesn't now.
Function ScrambleText(Thetext As String)
should be
Function ScrambleText(Thetext As String) As String
also, try this way
ScrambleText (Text1.Text)
without the parenthesis