Results 1 to 7 of 7

Thread: [RESOLVED] how can generate such arry number

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    17

    Resolved [RESOLVED] how can generate such arry number

    I want to generate such array number,guys,pls,
    001
    002
    003
    004
    005
    ....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how can generate such arry number

    If you need the leading zeroes then you can't use numbers because numbers don't have leading zeroes. You'd have to use strings:
    vb.net Code:
    1. Dim numbers(n - 1) As String
    2.  
    3. For counter As Integer = 1 To n
    4.     numbers(n - 1) = counter.ToString("000")
    5. Next
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    17

    Re: how can generate such arry number

    thanks jmcilhinney, I used codes you provided, and I try some codes like below,

    Dim n As integer
    n = TextBox1.Text
    Dim numbers(n - 1) As String

    For counter As Integer = 1 To n
    numbers(n - 1) = counter.ToString("000")
    Next

    TextBox2.Text = numbers(n - 1)

    it does only show the number I input into the textbox1 and prefix ,

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how can generate such arry number

    That would be because you're only showing the last number in the sequence. 'numbers' is an array with n elements and you're only showing the one at index (n - 1), i.e. the last one. If you want to see them all try doing this:
    vb.net Code:
    1. MessageBox.Show(String.Join(ControlChars.NewLine, numbers))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    17

    Re: how can generate such arry number

    thanks a again, but actually, I could not figure our where my mistake is with your help, for example, I input the "7" at textbox1, and results screen like as below

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim n As Integer
    n = TextBox1.Text
    Dim numbers(n - 1) As String
    For counter As Integer = 1 To n
    numbers(n - 1) = counter.ToString("000")
    Next
    MessageBox.Show(String.Join(ControlChars.NewLine, numbers))

    Last edited by vbsunst; May 13th, 2009 at 02:07 AM. Reason: wrong image address

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how can generate such arry number

    Sorry, my mistake. That should have been
    Code:
    numbers(counter - 1) = counter.ToString("000")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    17

    Re: how can generate such arry number

    thanks for your great help, it works fine now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width