Results 1 to 7 of 7

Thread: Spell Backwards Function

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    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

  2. #2
    Addicted Member
    Join Date
    May 2000
    Posts
    142

    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.

  3. #3
    Guest
    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

  4. #4
    Lively Member
    Join Date
    May 1999
    Location
    KC
    Posts
    72
    You could just use VB's StrReverse(string) function.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80

    Smile Thanks a bunch

    Appreciate the help guys.

    -Jack Vinitsky

  6. #6
    Lively Member
    Join Date
    Jul 2000
    Posts
    82
    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

  7. #7
    Guest

    Wink 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
  •  



Click Here to Expand Forum to Full Width