I want to generate such array number,guys,pls,
001
002
003
004
005
....
Printable View
I want to generate such array number,guys,pls,
001
002
003
004
005
....
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:
Dim numbers(n - 1) As String For counter As Integer = 1 To n numbers(n - 1) = counter.ToString("000") Next
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 ,
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:
MessageBox.Show(String.Join(ControlChars.NewLine, numbers))
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))
http://img16.imageshack.us/img16/9241/screendtg.jpg
Sorry, my mistake. That should have beenCode:numbers(counter - 1) = counter.ToString("000")
thanks for your great help, it works fine now