2 Replies - 6367 Views - Last Post: 31 October 2010 - 10:04 PM Rate Topic: -----

#1 good_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-October 10

reading text file line by line in VB.net

Posted 31 October 2010 - 08:51 PM

Good Day ...

i am doing program to read text file and fill the data to multi array , in my code i tried to read the first line of text file to array (here i used class) to save this data on it, because i will use it to read the another lines ,
files have the following format (all numbers are integers, all intra-line separators are spaces):
First line: Number of events, number of rooms, number of features, number of students
after the first line as u see we have 3 line have 10 which mean the One line for each room:Roomsize
and after that the line which start from zeros and ones it format as:-
4 3 3 2
10
10
10
0
0
0
0
0
0
0
0

*One line for each student/event:
A zero or one. Zero means that the student does NOT attend the event, one means that he DOES attend the event.
In the order of these the event changes more quickly.
For example, if there were students and events then the following

0

1

0

0

1

1

0

0

0

0

1

0

would give this attends matrix:
Attached Image

Meaning:

the first student attends the second event
the second student attends the first and second events
the third student attends the third event
----
and after that the
*One line for each room/feature:

A zero if the room does NOT satisfy the feature, or a one if the room DOES satisfy the feature.
In the order of these the feature changes more quickly. by build the same matrix above but with diff meaning as i said ..
-----
and after that One line for each event/feature:
A zero if the event does NOT require the feature, or a one if it DOES.
In the order of these the feature changes more quickly.
and also build matrix it have event\feature , for more description on this site here Input Format
-------
so here i am trying to build 3 matrix depending to the dataset Sequentially ..
i am sorry about all this presentation :) but i tried to explain what i want to do ..
and this is my code so far ,, i just start today and i hope if i can find any suggestion or advise

Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
    Public number As New firstline
    Dim array1() As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Try
            'Dim k As Integer
            ' Loop through each line in array returned by ReadAllLines
            Dim line As String
            For Each line In File.ReadAllLines("c:\dataset.txt")

                ' Split line on comma
                Dim parts As String() = line.Split(New Char() {" "c})
                Dim lines As String() = parts

                ' Loop over each string received
                ' Display to Console
                Select Case i
                    Case 0
                        '  array1(k) = parts(k)
                        ' MsgBox(parts(1))
                        number.Number_events = parts(0)
                        number.number_features = parts(1)
                        number.number_rooms = parts(2)
                        number.number_students = parts(3)
                        TextBox2.Text = number.Number_events
                        TextBox3.Text = number.number_features
                        TextBox4.Text = number.number_rooms
                        TextBox5.Text = number.number_students

                End Select

                For i = 1 To number.number_rooms
                    TextBox1.Text = parts(i)
                    ' i know here it is wrong i just want to chech every things , i just used textbox to see the result 
                    ' so here the i will start from 1 untill the number of rooms here is 3

                    ' MsgBox(" number of room " & vbCrLf & number.number_rooms)


                Next
                TextBox1.Text = lines(5)
                'MsgBox(part)


                'For jj As Integer = 0 To 3
                '   array1(jj) = part
                'Next jj
                'TextBox2.Text = array1(2)
                ' TextBox1.Text = number.number_rooms
                'TextBox1.Text = ("{0}:{1}" & vbCrLf & i & vbCrLf & part)
                ' MsgBox(part)
                ' For s As Integer = 0 To 3

                'Next
            Next
            i += 1

            For k As Integer = 0 To number.number_rooms - 1
                MessageBox.Show(array1(k))


            Next


        Catch ex As Exception

        End Try
        'MessageBox.Show(number.number_rooms)

    End Sub
End Class



Public Class firstline
    Public Number_events As Integer
    Public number_rooms As Integer
    Public number_features As Integer
    Public number_students As Integer

End Class



and thanks for every thing ..
God bless u all ..

Is This A Good Question/Topic? 0
  • +

Replies To: reading text file line by line in VB.net

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: reading text file line by line in VB.net

Posted 31 October 2010 - 09:22 PM

Look at using a streamreader, which allows you to read the stream (file) by line.
Was This Post Helpful? 0
  • +
  • -

#3 good_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-October 10

Re: reading text file line by line in VB.net

Posted 31 October 2010 - 10:04 PM

i used streamreader before but it will take a long time to read ..
thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1