Hi all,
I need help writing a function, that when passed a string, will return it with the letters reversed.
For example:
If I pass it "Basic", it returns "cisaB".
Thanks in advance for any help.
-Jack Vinitsky
Printable View
Hi all,
I need help writing a function, that when passed a string, will return it with the letters reversed.
For example:
If I pass it "Basic", it returns "cisaB".
Thanks in advance for any help.
-Jack Vinitsky
Code:function reverse(myString as string) as string
dim temp as string
last = Len(myString)
for i = last to 1 step -1
cur = Mid(myString,i,1)
temp = temp & cur
next
reverse = temp
end function
If you have VB6, use the strReverse Function.
If you do not have VB6, here is the VB5 or VB4 equivilant.Code:MyString = "Hello"
RetVal = StrReverse(MyString)
Print RetVal
Code:Public Function StrReverse(ByVal sIn As String) As String
Dim nC As Integer, sOut As String
For nC = Len(sIn) To 1 Step -1
sOut = sOut & Mid(sIn, nC, 1)
Next
StrReverse = sOut
End Function
You could just use VB's StrReverse(string) function.
Appreciate the help guys.
-Jack Vinitsky
hi,
here is a program that can do as you asked:
Option Explicit
Dim Letter,Reword As String
Dim lenWord, i As Byte
Public Sub RevWord(Word As String)
ReWord = ""
i = 0
lenWord = Len(Word)
Letter = Mid(Word, lenWord, 1)
ReWord = ReWord & Letter
Do
i = i + 1
If i = lenWord Then Exit Sub
Letter = Mid(Word, lenWord - i, 1)
ReWord = ReWord & Letter
Loop
End Sub
Private Sub Command1_Click()
RevWord X ' X is the word like : "Hi"
End Sub
this program will return the reversed word in the ReWord string.
hope i helped, bye
Private Text.Click()
Text = Text
End Sub
Guaranteed to reverse your string for you...at least in version 5