How Do You rearrange letters in a string?

Posted on 2003-03-02
Medium Priority
Last Modified: 2011-10-03
What i mean is say i have a string "ASDFGH". How do you randomly rearrange them so they may appear in any order? eg FSGADH or DHFSGA?
Question by:Wombatz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Accepted Solution

aelatik earned 200 total points
ID: 8051316
'This function will do for you....
' Put a command button on your form and paste this code.

Private Sub Command1_Click()
MsgBox ReArrange("ASDFGH")
End Sub

Function ReArrange(Words As String)
Dim MyOutput As String
Dim MyString As String
Dim MyRandomNR As Long
    MyString = Words
    For i = 1 To Len(MyString)
    MyRandomNR = Int(Len(MyString) * Rnd + 1)
    If MyString <> "" Then MyOutput = MyOutput & Mid(MyString, MyRandomNR, 1)
    MyString = Left(MyString, MyRandomNR - 1) & Right(MyString, Len(MyString) - MyRandomNR)
    ReArrange = MyOutput
End Function

'happy programming :-)

Author Comment

ID: 8051404
Works like a charm...
I implemented one too..but just geenrating two no.s withinthe string and then swapping them. And repeating this step a few times
haha..but this is definitely better!
LVL 14

Expert Comment

ID: 8051663

If the answer fits your question then click on "accept this answer"

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question