Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. reading data from txt file

reading data from txt file

Scheduled Pinned Locked Moved Visual Basic
csharphelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amanjot
    wrote on last edited by
    #1

    Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot

    B F 2 Replies Last reply
    0
    • A Amanjot

      Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot

      B Offline
      B Offline
      Brian Van Beek
      wrote on last edited by
      #2

      Do you know how many inputs you are going to have in the file. If you don't it will be a little difficult. This sounds like a perfect time to use a Vector to me. Brian Van Beek My Blog is Awesome, ok maybe not, but is still fun!!

      A 1 Reply Last reply
      0
      • A Amanjot

        Hi! Looks I have a very simple problem, buts its killing me. I want to read data from a text file and put it to a unique variable. For example: data in Text file looks like 10 20 50 60 20 40 60 20 80 90 I want to read so that say a=10, b=20, c=50, d=60, e=20, f=40 and so forth. usually in fortran etc. it used to be simple: read a,b,c,d,e,f.... How should it work in vb.net Thanks. Amanjot

        F Offline
        F Offline
        Fernando Soto
        wrote on last edited by
        #3

        Hi Amanjot; Here is one way to do it. ' Array to hold each number in the file Dim intArray(0) As Integer ' Line of numers read from file Dim inputText As String ' String to hold each value from input line Dim splitText(20) As String ' Index into integer array Dim index As Integer = 0 ' Size of integer array holding values Dim arraySize As Integer = -1 Dim reader As StreamReader = New StreamReader("c:\temp\integerfile.txt") Do ' Read a line of text from file inputText = reader.ReadLine ' Parse the line of integers splitText = inputText.Split(" ") ' Calculate the size need for new values arraySize += splitText.Length ' Resize the array to hold new values ReDim Preserve intArray(arraySize) ' Put each value into a unique variable For Each numberString As String In splitText intArray(index) = CInt(numberString) index += 1 Next ' ChecK to see if there are any more input Loop Until reader.Peek = -1 .... reader.Close() I hope that this was of some help -Fernando :)

        1 Reply Last reply
        0
        • B Brian Van Beek

          Do you know how many inputs you are going to have in the file. If you don't it will be a little difficult. This sounds like a perfect time to use a Vector to me. Brian Van Beek My Blog is Awesome, ok maybe not, but is still fun!!

          A Offline
          A Offline
          Amanjot
          wrote on last edited by
          #4

          yah! I know how many inputs are there in the file. Infact, its a formatted file i.e place for each variable is defined. for example, sequence of vaiable will be a,b,c,d in first line and e,f,g in second and h, i, j in third and so on. Thanks. amanjot

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups