To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Oct 26th, 2006, 10:51 PM   #1
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 26th, 2006, 11:02 PM   #2
Tontow
Addicted Member
 
Join Date: Oct 06
Posts: 172
Tontow is an unknown quantity at this point (<10)
Re: Read/write files in VB

It would help if you attached the source file or at least posted a sample of it.
Tontow is offline   Reply With Quote
Old Oct 26th, 2006, 11:13 PM   #3
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 27th, 2006, 01:05 AM   #4
gavio
PowerPoster
 
gavio's Avatar
 
Join Date: Feb 06
Location: GMT+1
Posts: 4,426
gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)
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...
gavio is offline   Reply With Quote
Old Oct 27th, 2006, 01:37 AM   #5
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 27th, 2006, 01:42 AM   #6
gavio
PowerPoster
 
gavio's Avatar
 
Join Date: Feb 06
Location: GMT+1
Posts: 4,426
gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)
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.
gavio is offline   Reply With Quote
Old Oct 27th, 2006, 01:49 AM   #7
RobDog888
Super Moderator
 
RobDog888's Avatar
 
Join Date: Apr 01
Location: LA, Calif. Raiders #1 AKA:Gangsta Yoda™
Posts: 58,875
RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)
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, 2007, 2008, 2009, 2010
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
RobDog888 is offline   Reply With Quote
Old Oct 27th, 2006, 02:05 AM   #8
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 27th, 2006, 02:14 AM   #9
RobDog888
Super Moderator
 
RobDog888's Avatar
 
Join Date: Apr 01
Location: LA, Calif. Raiders #1 AKA:Gangsta Yoda™
Posts: 58,875
RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)RobDog888 has a brilliant future (2000+)
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, 2007, 2008, 2009, 2010
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista (New)Multiple .NET Framework Versions (New)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 Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
RobDog888 is offline   Reply With Quote
Old Oct 27th, 2006, 04:52 AM   #10
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 27th, 2006, 06:24 AM   #11
gavio
PowerPoster
 
gavio's Avatar
 
Join Date: Feb 06
Location: GMT+1
Posts: 4,426
gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)
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.
gavio is offline   Reply With Quote
Old Oct 27th, 2006, 06:42 AM   #12
chthong
Lively Member
 
Join Date: Feb 06
Posts: 64
chthong is an unknown quantity at this point (<10)
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?
chthong is offline   Reply With Quote
Old Oct 27th, 2006, 12:52 PM   #13
gavio
PowerPoster
 
gavio's Avatar
 
Join Date: Feb 06
Location: GMT+1
Posts: 4,426
gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)gavio is a jewel in the rough (300+)
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.
gavio is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:23 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.