Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > open text file and read from last data first until first data


Reply
 
Thread Tools Display Modes
  #1  
Old 10-05-2005, 11:24 PM
jazmiey jazmiey is offline
Newcomer
 
Join Date: Oct 2005
Posts: 10
Default open text file and read from last data first until first data


usually open file for read text file read from first data until last data right?
now i want to do is read last data first in text file until first data.

thank you

Last edited by italkid; 10-06-2005 at 01:18 AM. Reason: Removed offline help request (e-mail address).
Reply With Quote
  #2  
Old 10-06-2005, 12:02 AM
DJ_Klepc's Avatar
DJ_Klepc DJ_Klepc is offline
Contributor
 
Join Date: Apr 2004
Location: Slovenia
Posts: 602
Default

You can read text file normaly and then use StrReverse function which will reverse whole string so it will look like you read file from end to start.
__________________
DJ_Klepc
My HomePage
My e-Mail
Reply With Quote
  #3  
Old 10-06-2005, 01:05 AM
jazmiey jazmiey is offline
Newcomer
 
Join Date: Oct 2005
Posts: 10
Default

for your information my system is i write serial no in text file and continues append writing to this file.when new serial no want to save to this file,the system must check it first is it already exist or not in this file.but it only check 50 serial no from the last data to up data.

inside this file not only serial no but also write time,serial no,and so on

the problem is how to read from the last data to first 50 data from last data?no need read first all the data.just until 50th from last data.

thank you

Quote:
Originally Posted by jazmiey
usually open file for read text file read from first data until last data right?
now i want to do is read last data first in text file until first data.

thank you

Last edited by italkid; 10-06-2005 at 01:18 AM.
Reply With Quote
  #4  
Old 10-06-2005, 01:56 AM
DJ_Klepc's Avatar
DJ_Klepc DJ_Klepc is offline
Contributor
 
Join Date: Apr 2004
Location: Slovenia
Posts: 602
Default

Oh that! Say So!
You can use binary access and go from last character to first, Character by character. Then store this characters together so you will get the text you need.

Code:
Open File for Binary as #1 for i= filelen to 1 Step -1 get #1, i, character text=i & text ' check if text is data you need and if it is then exit for next i
__________________
DJ_Klepc
My HomePage
My e-Mail
Reply With Quote
  #5  
Old 10-06-2005, 07:28 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

If there's a fixed number of bytes per entry, get the file length,subtract the (bytes-per-entry * 50) and read. Then, search.

Since you're validating the serial number every time, this would probably be a good use for a simple database storage, like Access. If you set a primary or unique key on the serial number, ADO wouldn't allow a duplicate entry.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->