Need Help with Leading Zeros

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bIGMOS
    New Member
    • Dec 2007
    • 5

    Need Help with Leading Zeros

    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
  • Torgg
    New Member
    • Dec 2007
    • 41

    #2
    If I understand your question, this should get you what you want.

    Code:
            Dim oRand As New Random()
            Dim iRand1 As Integer
            iRand1 = oRand.Next(100, 999)
    
            TextBox1.Text = (iRand1.ToString("000#"))
    Hope this helps,
    Torgg

    Comment

    • bIGMOS
      New Member
      • Dec 2007
      • 5

      #3
      Originally posted by Torgg
      If I understand your question, this should get you what you want.

      Code:
              Dim oRand As New Random()
              Dim iRand1 As Integer
              iRand1 = oRand.Next(100, 999)
      
              TextBox1.Text = (iRand1.ToString("000#"))
      Hope this helps,
      Torgg
      Yep that did it Thanks for your help . I was overcomplicatin g it.

      Comment

      Working...