|
-
May 12th, 2009, 11:39 PM
#1
Thread Starter
Junior Member
[RESOLVED] how can generate such arry number
I want to generate such array number,guys,pls,
001
002
003
004
005
....
-
May 12th, 2009, 11:44 PM
#2
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:
Dim numbers(n - 1) As String For counter As Integer = 1 To n numbers(n - 1) = counter.ToString("000") Next
-
May 13th, 2009, 12:18 AM
#3
Thread Starter
Junior Member
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 ,
-
May 13th, 2009, 12:25 AM
#4
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:
MessageBox.Show(String.Join(ControlChars.NewLine, numbers))
-
May 13th, 2009, 02:02 AM
#5
Thread Starter
Junior Member
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
-
May 13th, 2009, 02:07 AM
#6
Re: how can generate such arry number
Sorry, my mistake. That should have been
Code:
numbers(counter - 1) = counter.ToString("000")
-
May 13th, 2009, 02:13 AM
#7
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|