Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Randomize()


Reply
 
Thread Tools Display Modes
  #1  
Old 08-25-2004, 01:26 PM
vbjohn vbjohn is offline
Newcomer
 
Join Date: Apr 2004
Location: Minneapolis, MN
Posts: 2
Default Randomize()


On this part of my code I am doing a randomized letter generator. What is going on is that it comes out duplicate. How can I fixed it?

FOR i = 1 to 2
Randomize()
For forUserIdCharacterCount = 1 To 80
rndNewUserIdCharacter = Int((90 - 65 + 1) * Rnd() + 65)
strNewUserId = strNewUserId & Chr(rndNewUserIdCharacter)
Next
Next
Reply With Quote
  #2  
Old 08-25-2004, 01:43 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Take the Randomize out and put it once in the Form_Load. Then see if the problem continues. Randomize should only be called once.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #3  
Old 08-25-2004, 01:43 PM
ElderKnight ElderKnight is offline
Senior Contributor

Forum Leader
 
Join Date: Oct 2003
Location: Central Florida
Posts: 1,204
Default

Quote:
Originally Posted by vbjohn
On this part of my code I am doing a randomized letter generator. What is going on is that it comes out duplicate. How can I fixed it?

FOR i = 1 to 2
Randomize()
For forUserIdCharacterCount = 1 To 80
rndNewUserIdCharacter = Int((90 - 65 + 1) * Rnd() + 65)
strNewUserId = strNewUserId & Chr(rndNewUserIdCharacter)
Next
Next
I think you *are* getting new letters appended to your string at the end, but because you're not clearing it out (e.g., strNewUserId = "", maybe just bnefore the second "For") you're not seeing them -- they're off the far right of the screen.

You should also move the Randomize statement out of that loop. Call it only once at program start.
__________________
-- D.J.

I do not endorse any items advertised within this frame, and regret that the viewer is subjected to such.
Reply With Quote
  #4  
Old 08-25-2004, 01:47 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

You'll probably need to flush strNewUserId after it's used. You are adding the second random number string to the end of the first.

Plus, as Elderknight said, the randomize sub should only be used onec in the life of your project.

Edit: Whoops. WAYYYY too late!
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->