| | |
Help Please, how do i read from text file into array?
![]() |
•
•
Join Date: Feb 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi I'm stuck on a project using VB 2005 express edition. I'm having trouble reading in data into my code from a Text File.
I'm using an openFileDialog so the user can select a file to open. The opened file will contain 3 columns and an unknown number of rows. I want to read the data from the file calling the first colum x, second y, and third z. I then want to plot a graph of the raw data (x,y). Before performing simple mathematical equations on each row of x,y and z and sum the answers.
Unfortunately so far I can't get past inputing the data into the program, so I'd be very grateful for any help you can give me.
I'm using an openFileDialog so the user can select a file to open. The opened file will contain 3 columns and an unknown number of rows. I want to read the data from the file calling the first colum x, second y, and third z. I then want to plot a graph of the raw data (x,y). Before performing simple mathematical equations on each row of x,y and z and sum the answers.
Unfortunately so far I can't get past inputing the data into the program, so I'd be very grateful for any help you can give me.
vb Syntax (Toggle Plain Text)
Public Class Form1 Dim data(i, 2) As String Dim g, filename As String Dim i, numlines, lines, As Integer Dim x(i), y(i), s(i) As Double Private Sub OpenFileBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileBtn.Click If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then 'opens file of users choice if cancel not pressed FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) lines = getNumLines(1) FileClose(1) FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input) ReDim data(lines, 2) For i = 0 To i = lines - 1 Input(1, data(i, 0)) Input(1, data(i, 1)) Input(1, data(i, 2)) x(i) = Val(data(i, 0)) y(i) = Val(data(i, 1)) s(i) = Val(data(i, 2)) Graph1.Plotxy(x(i), y(i)) Next i FileClose(1) End If End Sub Public Function getNumLines(ByVal fileName As Integer) As Integer Dim numLines As Integer numLines = 0 While Not (EOF(1)) numLines = numLines + 1 'counts number of rows in the file Input(1, g) End While Return numLines 'return the number of lines found End Function End Class
Last edited by WaltP; Feb 11th, 2007 at 3:02 am. Reason: Added code tags so we can read your code
![]() |
Similar Threads
- Reading from text file into array (C++)
- Help with a 2D array from a text file (C++)
- Need Help in Reading characters from a text file (C++)
- Read in a string from a text file (C)
- Inputting text file data into an array, please help! (C++)
- how do i read the last line of a text file? (Python)
- Help Reading Info in Text File Into an Array (C++)
- URGENT - Reading from txt file into a 2 dimension array (Java)
- Read and write to an ASCII Text file (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how can I display pdf file inside the ole container control
- Next Thread: ListView Help..
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





