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. how to read the value from a text file?

how to read the value from a text file?

Scheduled Pinned Locked Moved Visual Basic
algorithmsdata-structureshelptutorialquestion
5 Posts 2 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.
  • E Offline
    E Offline
    ESJY
    wrote on last edited by
    #1

    I m new to VB 6 programming and i have encountered some problems. I have to load a text file into the program and search through the file to find a keyword 'entities'. When the program reaches the keyword, it has load some values at different lines of this text file into the program array. This is one of the possible algorithm i have thought of: 1.Select the file 2.Search through the file for keyword 'Entities' 3.Load the values into the array. However, i am stuck in step 2. Could anyone of you please give me some suggestions on how to complete step 2 and step 3?? Thankyou so much. Esther

    S 1 Reply Last reply
    0
    • E ESJY

      I m new to VB 6 programming and i have encountered some problems. I have to load a text file into the program and search through the file to find a keyword 'entities'. When the program reaches the keyword, it has load some values at different lines of this text file into the program array. This is one of the possible algorithm i have thought of: 1.Select the file 2.Search through the file for keyword 'Entities' 3.Load the values into the array. However, i am stuck in step 2. Could anyone of you please give me some suggestions on how to complete step 2 and step 3?? Thankyou so much. Esther

      S Offline
      S Offline
      steff kamush
      wrote on last edited by
      #2

      ESJY, b sure include a button (Command1) on your form. not sure wat step 3 is about.. Option Explicit Option Base 1 '//start array at index 1 Option Compare Text Private vArray() As Variant '//array of variants - can b specified Private Sub Command1_Click() Dim vVariable1 As Variant 'Dim iFile As Integer Dim i As Integer Open "c:\sample.txt" For Input As #1 'iFile While Not EOF(1) Input #1, vVariable1 If (vVariable1 Like "*Entities*") Then i = i + 1 ReDim Preserve vArray(i) As Variant vArray(i) = vVariable1 MsgBox vArray(i) End If Wend Close #1 'iFile End Sub :rose::rose:

      E 1 Reply Last reply
      0
      • S steff kamush

        ESJY, b sure include a button (Command1) on your form. not sure wat step 3 is about.. Option Explicit Option Base 1 '//start array at index 1 Option Compare Text Private vArray() As Variant '//array of variants - can b specified Private Sub Command1_Click() Dim vVariable1 As Variant 'Dim iFile As Integer Dim i As Integer Open "c:\sample.txt" For Input As #1 'iFile While Not EOF(1) Input #1, vVariable1 If (vVariable1 Like "*Entities*") Then i = i + 1 ReDim Preserve vArray(i) As Variant vArray(i) = vVariable1 MsgBox vArray(i) End If Wend Close #1 'iFile End Sub :rose::rose:

        E Offline
        E Offline
        ESJY
        wrote on last edited by
        #3

        thanks kamush, that really helps... how many variable can be stored in the array?? because the file to be loaded is a very large file and therefore there is quite a number of variables to be read into the array.

        S 1 Reply Last reply
        0
        • E ESJY

          thanks kamush, that really helps... how many variable can be stored in the array?? because the file to be loaded is a very large file and therefore there is quite a number of variables to be read into the array.

          S Offline
          S Offline
          steff kamush
          wrote on last edited by
          #4

          Hi ESJY, an array is jus memory space, so it can take quite alot but slows down your app, right? wat do u want the array for? u could read 5 lines after the keyword n display it (or whatever u wanna do). jus depends on wat u want Esther.. While Not EOF(1) Line Input #1, vVariable1 '//reads whole line If (vVariable1 Like "*Entities*") Then i = i + 1 if (i=5) then i=1 ReDim vArray(i) As Variant '//reset array wit 1 item.. else ReDim Preserve vArray(i) As Variant end if vArray(i) = vVariable1 ListBox1.AddItem vArray(i) End If Wend :rose::rose:

          E 1 Reply Last reply
          0
          • S steff kamush

            Hi ESJY, an array is jus memory space, so it can take quite alot but slows down your app, right? wat do u want the array for? u could read 5 lines after the keyword n display it (or whatever u wanna do). jus depends on wat u want Esther.. While Not EOF(1) Line Input #1, vVariable1 '//reads whole line If (vVariable1 Like "*Entities*") Then i = i + 1 if (i=5) then i=1 ReDim vArray(i) As Variant '//reset array wit 1 item.. else ReDim Preserve vArray(i) As Variant end if vArray(i) = vVariable1 ListBox1.AddItem vArray(i) End If Wend :rose::rose:

            E Offline
            E Offline
            ESJY
            wrote on last edited by
            #5

            oh... Thanks a lot... in fact i need an array to store information to be excuted by a machine. Anyway, thanks a lot for ur help. Merry Christmas and HAppy New Year:-D

            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