0

我需要0 - 9999在 VB 中计算。如何制作格式0000 - 9999,以便输出为:

0000, 0001, 0002, 0003, .......

我使用了以下代码

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

但我会用另一种方式来做。任何的想法?

4

3 回答 3

3

可能会ToString()有所帮助。怎么样

myint.ToString("0000")

或者

myint.ToString("D4");
于 2013-02-07T08:40:03.583 回答
3
For i as integer = 0 to 9999
     Debug.WriteLine(i.ToString("0000"))
next

未经测试的代码,但应该可以工作......

于 2013-02-07T08:40:36.247 回答
2

您的向导

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
于 2013-02-07T08:46:26.263 回答