• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Reversing the text

i have got a multilinetext. i would like to reverse the text i.e mirror image of the text is to be obtained.
for example if i have

this
an
expert

in 3 seperate lines then i should get the result as

siht
na
trepxe

in 3 seperate lines into another textbox. please help me out.i want the coding in Visual basic. I require it urgently.
0
ayesha16
Asked:
ayesha16
  • 2
  • 2
  • 2
  • +7
1 Solution
 
Ryan ChongCommented:
First, try use the Split function to split the text, then use the StrReverse function to reverse the text..
0
 
TimCotteeCommented:
Hi ayesha16,

    Dim aryLines() As String
    aryLines = Split(Text1.Text, vbNewLine)
    For i = LBound(aryLines) To UBound(aryLines)
        strText = ""
        For c = 1 To Len(aryLines(i))
            strText = Mid(aryLines(i), c, 1) & strText
        Next
        Text2.Text = Text2.Text & strText & vbNewLine
    Next

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
Ryan ChongCommented:
Here is an example:

Private Sub Command1_Click()
    Dim tmp As String, filePath As String
    Dim tmpArr() As String
    Dim newContent As String
    filePath = OpenDialog(Me)
    If filePath <> "" Then
       
        tmp = ReadFileText(filePath)
       
        tmpArr = Split(tmp, vbCrLf, , vbTextCompare)
       
        For i = 0 To UBound(tmpArr)
            If i <> 0 Then
                newContent = newContent & vbCrLf & StrReverse(tmpArr(i))
            Else
                newContent = StrReverse(tmpArr(i))
            End If
        Next i
       
        WriteFileText "C:\abc.txt", newContent
        MsgBox "Done!"
       
    End If
   
End Sub

Private Function ReadFileText(ByVal FileName As String) As String
    On Error GoTo EHandler
    Dim Handle As Integer
    Handle = FreeFile
    Open FileName For Input As #Handle
        ReadFileText = Input$(LOF(Handle), Handle)
        On Error Resume Next
    Close #Handle
    Exit Function
EHandler:
    ShowErrMsg
    On Error Resume Next
    Close #Handle
End Function

Public Function WriteFileText(ByVal FileName As String, ByVal Source As String) As String
    On Error GoTo EHandler
    Dim Handle As Integer
    Handle = FreeFile
    Open FileName For Output As #Handle
        Print #Handle, Source
        On Error Resume Next
    Close #Handle
    Exit Function
EHandler:
    ShowErrMsg
    On Error Resume Next
    Close #Handle
End Function

cheers
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EDDYKTCommented:
Does it sound like homework?

How come sometime we provide the solution and sometime we ask the code and then provide the fix?

0
 
EDDYKTCommented:
I buy  ryancys's first idea only provide some guideline and let them figure out the problem. However,  ryancys provide solution later?
0
 
cocomobasicCommented:
Private Sub Command1_Click()
Dim str As String
Dim i As Integer
Dim char As String

    str = StrReverse(Text1.Text)

    For i = 1 To Len(str)
   
        char = Mid$(str, i, 1)
        If char = vbLf Then
       
            Text2.Text = Text2.Text & vbCrLf
           
        ElseIf char = vbCr Then
        Else
       
            Text2.Text = Text2.Text & char
       
        End If
   
    Next

End Sub

this is assuming you have both textbox the same length
0
 
ayesha16Author Commented:
thank u very musch for the answer provided. mmmmmy problem has been solved.
0
 
ayesha16Author Commented:
i have got a multilinetext. i would like to reverse the text i.e mirror image of the text is to be obtained.
for example if i have

this
an
expert

in 3 seperate lines then i should get the result as

siht
na
trepxe

in 3 seperate lines into the same textbox.I want the coding in Visual basic. I require it urgently.
0
 
vikram_c90Commented:
Ayesha, I think u must accept an answer whihc helped to solve your problem, so that that person can get the points for it.
0
 
Rogue_VBCommented:
any expert who thinks he is going to get any points here, think again!!!!

refer to this link for details:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/viewMember.jsp?mid=1003046

note all the open questions..
0
 
CleanupPingCommented:
ayesha16:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
  • 2
  • +7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now