CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2001
    Posts
    31

    Reading text file

    hi
    i am supposed to read a text file and write only particular data it in to a grid.the position of the particular data is being extracted from another file.i am using a textstream for this purpose. the problem here is every time i want to extract data i am opening the file because of which there are many loops. there is any method by which i can optimise my program.
    does anybody know about this
    thanks
    roopa



  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Reading text file

    you might consider read the file into a string variable for further processing

    HTH

    cksiow
    http://vblib.virtualave.net - share our codes


  3. #3
    Join Date
    Mar 2001
    Posts
    31

    Re: Reading text file

    hi
    The file may consist of more than 100 or even 1000 lines.The data i want may be at a particular line so i don't want to read every line.
    bye


  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Reading text file

    Read the file into an array at startup then search the array whenever you need to update the grid instead of reReading the file.

    John G

  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Reading text file

    Well, the best way to optimize your program has been suggested by John and cksiow, that is reading the data into a string variable. Then do the processing on the string instead of the file.

    Reading the file into a string can be done line by line or even the whole file in one shot. Line Input, Input() and Read() should be able to help your reading the data and FileSize() function will return the file size of an opened file (if i'm not mistaken).

    Good luck,
    -Cool Bizs

    Good Luck,
    -Cool Bizs

  6. #6
    Join Date
    Apr 2001
    Location
    Tamil Nadu,INDIA
    Posts
    6

    Re: Reading text file

    Hi,
    U can open the file using binary acces read method.So,u can open a file at once instead of looping thru line by line.Then,u can use split function for spliting the entire file into at array(Array of strings,ur delemiter of the split function is vbcrlf) and u can erase the array after finishing ur process.It will increase ur performance and reduce the memory load.


    umapathy


  7. #7
    Join Date
    Mar 2001
    Posts
    31

    Re: Reading text file

    Thanks a lot for for your suggestions.
    i was able to optimise my program as you told.Though i had thought of using arrays i was not very sure of it.
    Thanks
    roopa


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured