|
File Input Help
I'm having trouble opening a text file with my vb.net program. When I run the program and try to open a text file. It says the file could not be opened. Here's some of my code.
[PHP]Private Sub SelectFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectFileButton.Click
With OpenFileDialog1
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
readData(.FileName)
End If
End With
SelectFileTextBox.Text = OpenFileDialog1.FileName.ToString
End Sub
[/PHP]
[PHP]
Module Module1
Private Structure CoData
Dim Name As String
Dim Count As Int32
Dim Prices() As Decimal
End Structure
Dim Company As CoData()
Private coCount As Int32 = 0
Public Sub readData(ByVal readFileName As String)
Try
Dim fileHandler As New StreamReader(readFileName)
Do Until fileHandler.Peek = -1
If (IsNumeric(fileHandler.ReadLine()) = False) Then
Company(coCount).Name = fileHandler.ReadLine()
End If
ReDim Preserve Company(coCount).Prices(Company(coCount).Count + 1)
Company(coCount).Prices(Company(coCount).Count) = Convert.ToInt32(fileHandler.ReadLine())
coCount += 1
Loop
fileHandler.Close()
Catch
Dim msg As String
msg = "File could not be opened."
MessageBox.Show(msg, "Error", MessageBoxButtons.OK)
End Try
End Sub
End Module
[/PHP]
|