Solved

vb.net - generate number list

Posted on 2012-04-11
10
407 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
Comment Utility
1.ToString("D6") will produce 000001
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:yawkey13
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:yawkey13
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now