New topic: 

Generating a random string

<http://forums.realsoftware.com/viewtopic.php?t=38011>

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        CajunTechie          Post subject: Generating a random 
stringPosted: Wed Mar 09, 2011 2:48 am                         
Joined: Wed Sep 15, 2010 9:27 pm
Posts: 23                Hello Everyone,

I need to generate a random character string that contains a specific number of 
character (set by the user). While I thought the code below would work, it's 
not doing anything at all and I'm hoping someone can clue me in to what I'm 
doing wrong
Code:  Dim Number as Integer
  Dim SelectedNumber as Integer
  Dim Generator as New Random
  Dim Password as String
  Dim Characters as String = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+?/><."
  
 if cmbCharMix.Text = "Letters Only" then
  While Len(Password)  >= val(CharNum.Text)
  Number = Generator.InRange(1, 52)
  Password = Password + Mid(Characters, Number)
  wend
  GeneratedPassword.Text = Password
End if


CmbCharMix is a combo box that allows the user to select the type of string 
they want to generate. This will be handled my a modification to the If/Else 
block above and CharNum is a textbox containing a number that will specify the 
number of characters to generate in the password.

For some reason. NOTHING is happening in this block. NOTHING is being generated.

What am I doing wrong?   
                             Top                 timhare          Post subject: 
Re: Generating a random stringPosted: Wed Mar 09, 2011 3:29 am                  
       
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 9407
Location: Portland, OR  USA                I believe your test is backward:
Code:While Len(Password)  < val(CharNum.Text)

Since Password starts out at "", the original test (>=) will fail immediately.  
 
                             Top                CajunTechie          Post 
subject: Re: Generating a random stringPosted: Wed Mar 09, 2011 4:11 am         
                
Joined: Wed Sep 15, 2010 9:27 pm
Posts: 23                Thank you! Worked like a charm!   
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to