|
-
Jul 6th, 2000, 03:05 PM
#1
Thread Starter
Lively Member
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
-
Jul 6th, 2000, 03:19 PM
#2
Addicted Member
here you go
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
Secret to long life:
Keep breathing as long as possible.
-
Jul 6th, 2000, 03:21 PM
#3
If you have VB6, use the strReverse Function.
Code:
MyString = "Hello"
RetVal = StrReverse(MyString)
Print RetVal
If you do not have VB6, here is the VB5 or VB4 equivilant.
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
-
Jul 6th, 2000, 03:22 PM
#4
Lively Member
You could just use VB's StrReverse(string) function.
-
Jul 6th, 2000, 03:24 PM
#5
Thread Starter
Lively Member
Thanks a bunch
Appreciate the help guys.
-Jack Vinitsky
-
Jul 6th, 2000, 03:31 PM
#6
Lively Member
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
-
Jul 6th, 2000, 10:14 PM
#7
If using a txtBox let a MS bug fix it for you
Private Text.Click()
Text = Text
End Sub
Guaranteed to reverse your string for you...at least in version 5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|