Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles
Button3.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "Csv Files|*.csv|txt Files|*.txt"
openFileDialog1.Title = "Select a File to import numbers"
Dim convert As String = ""
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Using SR As New System.IO.StreamReader(openFileDialog1.FileName)
Dim All_lines As String = SR.ReadToEnd
convert = ("Button_" & All_lines)
'Label43.Text = convert
Me.Button_(convert).PerformClick()
End Using 'closes file
End If
End Sub
我有一个带数字的Csv文件:
2 五 6 14 25 36
我想在每个新行上导入一个Csv或Txt文件。 我的程序有相应的按钮
我正在尝试阅读每一行,这一切都很顺利 我有从Button_0到Button_36的按钮
我想做的就是Me.Button_(导入号码).PerformClick() 所以我从文件中读取了每一行 我想创建
Me.Button_2.PerformClick()
Me.Button_5.PerformClick()
Me.Button_6.PerformClick()
Me.Button_14.PerformClick()
Me.Button_25.PerformClick()
Me.Button_36.PerformClick()
enter code here
我不确定这是否可行 谢谢
答案 0 :(得分:0)
我自己发现了 我使用0-36的固定数字,并按每行比较数字,然后点击相应的按钮 这完全符合我的需要
如果openFileDialog1.ShowDialog()= System.Windows.Forms.DialogResult.OK那么
Using SR As New System.IO.StreamReader(openFileDialog1.FileName)
Do While SR.Peek() > -1
Dim Line As Integer = 0
Line = SR.ReadLine()
If Line = 0 Then
Me.Button_0.PerformClick()
End If
If Line = 1 Then
Me.Button_1.PerformClick()
End If
If Line = 2 Then
Me.Button_2.PerformClick()
End If
If Line = 3 Then
Me.Button_3.PerformClick()
End If
If Line = 4 Then
Me.Button_4.PerformClick()
End If
If Line = 5 Then
Me.Button_5.PerformClick()
End If
If Line = 6 Then
Me.Button_6.PerformClick()
End If
If Line = 7 Then
Me.Button_7.PerformClick()
End If
If Line = 8 Then
Me.Button_8.PerformClick()
End If
If Line = 9 Then
Me.Button_9.PerformClick()
End If
If Line = 10 Then
Me.Button_10.PerformClick()
End If
If Line = 11 Then
Me.Button_11.PerformClick()
End If
If Line = 12 Then
Me.Button_12.PerformClick()
End If
If Line = 13 Then
Me.Button_13.PerformClick()
End If
If Line = 14 Then
Me.Button_14.PerformClick()
End If
If Line = 15 Then
Me.Button_15.PerformClick()
End If
If Line = 16 Then
Me.Button_16.PerformClick()
End If
If Line = 17 Then
Me.Button_17.PerformClick()
End If
If Line = 18 Then
Me.Button_18.PerformClick()
End If
If Line = 19 Then
Me.Button_19.PerformClick()
End If
If Line = 20 Then
Me.Button_20.PerformClick()
End If
If Line = 21 Then
Me.Button_21.PerformClick()
End If
If Line = 22 Then
Me.Button_22.PerformClick()
End If
If Line = 23 Then
Me.Button_23.PerformClick()
End If
If Line = 24 Then
Me.Button_24.PerformClick()
End If
If Line = 25 Then
Me.Button_25.PerformClick()
End If
If Line = 26 Then
Me.Button_26.PerformClick()
End If
If Line = 27 Then
Me.Button_27.PerformClick()
End If
If Line = 28 Then
Me.Button_28.PerformClick()
End If
If Line = 29 Then
Me.Button_29.PerformClick()
End If
If Line = 30 Then
Me.Button_30.PerformClick()
End If
If Line = 31 Then
Me.Button_31.PerformClick()
End If
If Line = 32 Then
Me.Button_32.PerformClick()
End If
If Line = 33 Then
Me.Button_33.PerformClick()
End If
If Line = 34 Then
Me.Button_34.PerformClick()
End If
If Line = 35 Then
Me.Button_35.PerformClick()
End If
If Line = 36 Then
Me.Button_36.PerformClick()
End If
Loop