By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Need Help with Leading Zeros

bIGMOS
P: 5
I need to generate a random number from 0100, 0999, Im stuck on the how to..

iRand1 = oRand.Next(1000, 2500)
iRand2 = oRand.Next(1000, 9999)
iRand3 = oRand.Next(1000, 2500)
iRand4 = oRand.Next(9000, 9999)

TextBox1.Text = (iRand1)
TextBox2.Text = (iRand2)
TextBox3.Text = (iRand3)
TextBox4.Text = (iRand4)

I need iRand2 = oRand.Next(0100, 0999) t0 have leading zeros

Thanks in advance for any help
Jan 4 '08 #1
Share this Question
Share on Google+
2 Replies


P: 41
If I understand your question, this should get you what you want.

Expand|Select|Wrap|Line Numbers
  1.         Dim oRand As New Random()
  2.         Dim iRand1 As Integer
  3.         iRand1 = oRand.Next(100, 999)
  4.  
  5.         TextBox1.Text = (iRand1.ToString("000#"))
Hope this helps,
Torgg
Jan 4 '08 #2

bIGMOS
P: 5
If I understand your question, this should get you what you want.

Expand|Select|Wrap|Line Numbers
  1.         Dim oRand As New Random()
  2.         Dim iRand1 As Integer
  3.         iRand1 = oRand.Next(100, 999)
  4.  
  5.         TextBox1.Text = (iRand1.ToString("000#"))
Hope this helps,
Torgg
Yep that did it Thanks for your help . I was overcomplicating it.
Jan 4 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.