Reputation: 121
I need to count from 0 - 9999
in VB. How can I make the format 0000 - 9999
, so that the output is:
0000, 0001, 0002, 0003, .......
I used the following code
Dim p4num As Integer = 0
Dim p3num As Integer = 0
Dim p2num As Integer = 0
Dim p1num As Integer = 0
p4num += 1
If p4num = 10 Then
p4num = 0
p3num += 1
If p3num = 10 Then
p3num = 0
p2num += 1
If p2num = 10 Then
p2num = 0
p1num += 1
End If
End If
End If
but I would do it in another way. Any idea?
Upvotes: 0
Views: 4798
Reputation: 7092
Your guide
Dim numbers As IEnumerable(Of Integer) = Enumerable.Range(0, 9999).ToArray()
'object j = string.Join(", ", numbers);
For Each item As var In numbers
Console.WriteLine(item.ToString("#0000"))
Next
Upvotes: 2
Reputation: 2655
For i as integer = 0 to 9999
Debug.WriteLine(i.ToString("0000"))
next
Untested code, but should work...
Upvotes: 3
Reputation: 35477
The ToString()
may help. How about
myint.ToString("0000")
or
myint.ToString("D4");
Upvotes: 3