Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net - generate number list

Posted on 2012-04-11
10
Medium Priority
?
428 Views
Last Modified: 2012-06-27
hello there,
how can I generate a number list with 6 digits..
I would like to make a text list with number per line like this

000000
000001
000002
etc.. etc..
999999

how can i do that?
0
Comment
Question by:XK8ER
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37833711
1.ToString("D6") will produce 000001
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 37833712
something like this (ToString does the job):

        For I As Integer = 1 To 99
            ListBox1.Items.Add(I.ToString("000000"))
        Next
0
 
LVL 6

Expert Comment

by:yawkey13
ID: 37833714
Dim i
Dim numChars, padChar, strText
Dim list : list = ""
numChars = 6
padChar = "0"
For i = 0 to 999
      strText = i
      list = list & Right( String( numChars, padChar ) & strText, numChars ) & vbNewLine
Next
Wscript.echo list
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:yawkey13
ID: 37833727
The Wscript.echo will display the values from a vbs file on your desktop.  Change that line to output the list variable where you need it.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37834137
well i would do this to get the list:-

Dim lst = Enumerable.Range(1, 999999).[Select](Function(i) i.ToString(CultureInfo.InvariantCulture).PadLeft(6, "0"C)).ToList()

Open in new window

0
 
LVL 6

Expert Comment

by:yawkey13
ID: 37834271
BuggyCoder... I like it.  I didn't realize there was a build in PadLeft function.  Much cleaner than mine.  Can you explain what the "ToString(CultureInfo.InvariantCulture)" is doing?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37834371
this means your string is culture insensitive, read more here:-

http://msdn.microsoft.com/en-us/library/4c5zdc6a%28v=vs.90%29.aspx
0
 
LVL 1

Author Comment

by:XK8ER
ID: 37834909
tested all codes in here and they're not working..


>>list = list & Right( String( numChars, padChar ) & strText, numChars ) & vbNewLine
that line gives an error using VS2010 and vb.net



>>        For I As Integer = 1 To 99
>>            ListBox1.Items.Add(I.ToString("000000"))
>>        Next
that code works but only shows 99 records which is useless



and this line
>>Dim lst = Enumerable.Range(1, 999999).[Select](Function(i) i.ToString(CultureInfo.InvariantCulture).PadLeft(6, "0"C)).ToList()

gives and error too
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37834938
it works perfectly for me, are adding System.Globalization in your namespaces.
or simply do this:-

Dim lst = Enumerable.Range(1, 999999).[Select](Function(i) i.ToString().PadLeft(6, "0"C)).ToList()
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 37835011
check this out
Dim MyList As New List(Of String)
For x = 1 To 999999
    MyList.Add(x.ToString("D6"))
Next

Open in new window

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question