Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2006, 4:11 PM   #1
taporctv
Newbie
 
Join Date: Mar 2006
Posts: 20
Rep Power: 0 taporctv is on a distinguished road
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]
taporctv is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC