|
-
Apr 13th, 2009, 07:32 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] loops for less times
Hey,
The code below only loops for 3 times. I am assuming it should loop for six times right? Can someone tell me why please?
Code:
Private Sub RandomGenerator1()
Dim AscChr As String, ChrAsc As String
Dim counter As Integer = 0
txtRandom1.Text = ""
For counter = 0 To 5
Randomize()
AscChr = Abs(Int(64 - 122) * Rnd() - 64)
ChrAsc = Chr(AscChr)
txtRandom1.Text += String.Format(ChrAsc)
counter += 1
Next
End Sub
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 13th, 2009, 07:41 PM
#2
Re: loops for less times
You dont need the line
counter += 1
as this is effectively incrementing the counter value twice
-
Apr 13th, 2009, 08:16 PM
#3
Thread Starter
Frenzied Member
Re: loops for less times
heya,
Got confused with the C# loop. Many thanks
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Apr 13th, 2009, 08:46 PM
#4
Re: [RESOLVED] loops for less times
You're trying to create a random, 6-character string, correct?
vb.net Code:
Dim rng As New Random Dim min As Integer = Convert.ToInt32("A"c) Dim max As Integer = Convert.ToInt32("z"c) + 1 Dim chars(5) As Char For index As Integer = 0 To chars.GetUpperBound(0) chars(index) = Convert.ToChar(rng.Next(min, max)) Next MessageBox.Show(New String(chars))
Always use the Random class to generate random numbers, never Randomize() and Rnd().
-
Apr 15th, 2009, 03:55 AM
#5
Thread Starter
Frenzied Member
Re: [RESOLVED] loops for less times
Ok ,
Thanks for the advice. Can you pls tell me in why
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|