Results 1 to 13 of 13

Thread: Read/write files in VB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Question Read/write files in VB

    My friend need to do a application that able to read from a file to get some parameters for the application to run. The application will then generate some data into another text file (storing informations). The application should have limitation of the numbers of line for the content of the text files that can stored. Lets say the application will only stored 500 line for each text file, if the content of the text file reach 500 lines, it should automatically open another text file to write the content. When the program read back from the text files, it should get all the text files' content.

    Anyone have similar sampel program in VB? Thanks in advance.
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  2. #2
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: Read/write files in VB

    It would help if you attached the source file or at least posted a sample of it.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Re: Read/write files in VB

    The application haven't started yet. Thats why she need a sampel.
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Read/write files in VB

    There are countless samples about reading/writing from/to files all over the forums... just search for read and write...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Re: Read/write files in VB

    Code:
    The application should have limitation of the numbers of line for the content of the text files that can stored. Lets say the application will only stored 500 line for each text file, if the content of the text file reach 500 lines, it should automatically open another text file to write the content. When the program read back from the text files, it should get all the text files' content.
    How about this section?
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Read/write files in VB

    You can write to a file with a Print statement and increase a counter for 1 each time. When the counter reaches 500, go to the next file. The same goes for reading if you're doing it with a Line Input statement.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Read/write files in VB

    Here are a couple of threads in our FAQ forum.

    http://vbforums.com/showthread.php?t=342619
    http://vbforums.com/showthread.php?t=405051

    Gavio, the links you posted are searchid's which are temporary. I think they get deleted after a day or so.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Re: Read/write files in VB

    Code:
    You can write to a file with a Print statement and increase a counter for 1 each time. When the counter reaches 500, go to the next file. The same goes for reading if you're doing it with a Line Input statement.
    If i already storing records in 4 files (4 x 500 = 2000records)
    and i removed record in the first file, then it will not read for the rest of the file but only get the first 499 record?

    Can I use the UDP for storing in difference file?
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Read/write files in VB

    Sounds like you need to use a database if your storing multiple files and that number of records.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Re: Read/write files in VB

    I would like to but the server only allowed to stored using file system.
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  11. #11
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Read/write files in VB

    Quote Originally Posted by chthong
    If i already storing records in 4 files (4 x 500 = 2000records) and i removed record in the first file, then it will not read for the rest of the file but only get the first 499 record?
    Just out of couriosity... why are you limited to 500 records?
    Quote Originally Posted by chthong
    Can I use the UDP for storing in difference file?
    Yes, but then saving and loading a file is done by Put and Get, not Input and Print/Write, since it's a binary file.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    64

    Re: Read/write files in VB

    I also not sure, she didn't tell me why 500 records.
    Do you have examples storing UDP in multiple files? Thanks
    </HTML><SCRIPT>alert('Why job is so boring?')</SCRIPT>
    <?PHP
    $j=0;
    for($j=0;$j<=9999;$j++){
    echo 'Why job is so boring<BR>';
    }
    ?>
    Just want to test does it works?

  13. #13
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Read/write files in VB

    If this "records" are stored in one line per record, you can quite easly determine how many of theme are there:
    VB Code:
    1. Dim records As Integer
    2.     Open "c:\test1.txt" For Input As #1
    3.         records = UBound(Split(Input(LOF(1), 1), vbCrLf)) + 1
    4.     Close #1
    5.         Debug.Print "records: " & records
    Also, i think it's a waist of time to work with text files in this mather. It would be much much easier to do it with a database, as RobDog already sead.

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