Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How Do You rearrange letters in a string?

Posted on 2003-03-02
3
Medium Priority
?
890 Views
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?
THanks!!!
0
Comment
Question by:Wombatz
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
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)
    Randomize
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)
    Next
    ReArrange = MyOutput
End Function

'happy programming :-)
0
 

Author Comment

by:Wombatz
ID: 8051404
Thanks!
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!
0
 
LVL 14

Expert Comment

by:aelatik
ID: 8051663
Wombatz,

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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

571 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