Solved

vb.net - generate number list

Posted on 2012-04-11
10
408 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 69

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

947 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

21 Experts available now in Live!

Get 1:1 Help Now