我是vb.net的新手,我想创建一个包含多文件选项的简单程序。 我发现了这个YouTube视频:https://www.youtube.com/watch?v=8_pK0blSQr4 当我运行它时,迭代器会进行额外的迭代,从而导致错误。 我试图将for循环计数减1,但是没有用,for循环变为原始值。
我做错了什么?
Private Sub load_acc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles load_acc.Click
OpenFileDialog1.Filter = "Text file|*.txt|All files| *.*"
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
For x = 0 To (OpenFileDialog1.FileName.Count - 1)
acc_list.Items.Add(OpenFileDialog1.FileNames(x))
Next
End If
End Sub
答案 0 :(得分:2)
您可以使用每个
For each file as string in OpenFileDialog1.FileNames
acc_list.Items.Add(file)
Next
答案 1 :(得分:0)
我想你想要
For x = 0 To (OpenFileDialog1.FileNames.Count - 1)
(注意FileNames上的“s”)而不是
For x = 0 To (OpenFileDialog1.FileName.Count - 1)