Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何在vb中使用4位数_Vb.net - Fatal编程技术网

Vb.net 如何在vb中使用4位数

Vb.net 如何在vb中使用4位数,vb.net,Vb.net,我需要在VB中从0-9999开始计数。如何使格式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

我需要在VB中从
0-9999
开始计数。如何使格式
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
但我会用另一种方式。有什么想法吗?

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

myint.ToString("0000")

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

您的指南

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

在那里,我重新编辑了我的博文Richard SchneiderAm爵士,我也要使用Debug.writeline(I.ToString(“0000”)?这只是一个输出数字的示例方法。重要的部分是
.ToString(“0000”)
。您可以写入文件、控制台或…我已经有了正确的答案,
p1num.ToString(“D4”)
无论如何,谢谢:)我的帖子是如何将整数格式化为4位字符串@Mr47提供了完整的解决方案。这看起来像是C#而不是VB!
For i as integer = 0 to 9999
     Debug.WriteLine(i.ToString("0000"))
next
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