Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

this is how the file looks:

 

1 44.12345 25.56789 Ianca

2 41.78909 24.56789 Bechet

 

values are separated by "space"

 

for row 1 I have 44.12345 > var1 25.56789 > var2 Ianca > var3

 

etc....for the rest of the rows.

 

is a matter of life and death :)

  • Administrators
Posted

     Dim sr As New System.IO.StreamReader("c:\test.txt")
       Dim line As String
       Dim vals() As String

       Do
           line = sr.ReadLine()
           If line Is Nothing Then Exit Do
           vals = line.Split(" ")     'vals will contain an array of the data for each line.
       Loop While Not line Is Nothing

 

bit rough but should do the trick

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted (edited)

thanks, but how I take the values ?

 

for vals(1) I receive 41.78909 for 0 is ok...for 2 or 3 is ok..but the problem is that the array contain the last line (second line)

 

I can't extract from array elements from first line.

 

a little help here.....thanks

Edited by Ace Master
Posted (edited)

enter problem

 

I see that I have aother problem:

 

The vals(5) for ex. is the last from the line and this variable contain an "enter" , and I want to ignore this "enter" from the array.

 

One way is to take it out from the file source but it looks bad.

 

what I need to do ?:confused:

Edited by Ace Master
  • 1 month later...
Posted

I tried to make a bidimensional array to put some values like this :

 


      Dim sr As New System.IO.StreamReader("ace.txt")
      Dim vals() As Object
      Dim Line As Object

       Line = sr.ReadToEnd
       vals = Line.Split("," & vbCrLf)
       sr.Close()

 

text file is like this:

 

1,158

2,258

3,689

4,489

5,789

 

I whant this:

 

TextBox1.Text = vals(1)(2) to return 158

TextBox1.Text = vals(3)(2) to return 689

etc...

 

but..it seams not to work...

  • Leaders
Posted

you might want to try the ReadLine() property in this way ....

Dim sr As New System.IO.StreamReader(New System.IO.FileStream("C:\ace.txt",System.IO.FileMode.Open))

While Not sr.Peek()
   Console.WriteLine(sr.ReadLine.Split(",")(1))
   '/// you can use the Replace function here if you have returns to remove ( eg vbcrlf , chr(10) , chr(13) and so on )
   '/// for example Console.WriteLine(Replace(sr.ReadLine.Split(",")(1) , VbCrlf , "")) 
End While

sr.Close()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...