Solved

vb.net - generate number list

Posted on 2012-04-11
10
418 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

627 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