Solved

vb.net - generate number list

Posted on 2012-04-11
10
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 134
how to make search between pages 17 59
Need help with another query 10 54
Suppress if value zero or NULL in crystal report 2 43
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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