Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 10th, 2003, 09:45 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,861 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 23 m 55 sec
Reputation Power: 462
Newbisimo: VB6 File I/O Question

Although I have several years of experience with C/C++, I am just starting on VB6 through self-tuition. As part of that effort, I want to convert a C utility over to a VB6 application.

I have a text file containing several articles. Each article's title line starts with a unique character (@). My C utility scans the file for each title line, uses the ftell function to get its file pointer (its location within the file), and saves the title and its file pointer in a list. For now, the program picks a title at random, uses the fseek function to reposition to that article, and outputs the article to an output file. With VB, I would want to be able to review the list and pick out articles to output -- but that would be the easy part.

What are VB6 equivalents to ftell and fseek? How does one obtain one's position within a file and then reposition back to an arbitrary position?

Yes, I did try Google'ing for it, but with no success.

Also, since each paragraph is one line, I use an arbitrarily large string buffer in my C utility. Are strings in VB6 still limited to 255?

Reply With Quote
  #2  
Old October 10th, 2003, 11:00 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
So far as I know, yes. Interesting that you should make the transition from a C Programmer to VB. Most C Programmers I know are so anti-MS that they wouldn't even start an app if they knew it was written in VB... are you sure that you're not crossing the line to the dark side?

as for your question... I have no idea. You could try reading the line a character at a time in a loop - starting at the @ symbol and breaking at the next one, until EOF(FileNumber). Once you reach one of those conditions, you would have your constructed string and could put it in an array?
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old October 10th, 2003, 01:07 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,861 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 23 m 55 sec
Reputation Power: 462
Part of the situation is that I will be taking over somebody else's project, part of which was done in VB6. Besides, a VB app need not be entirely in VB; the real code can still be done in C and reside in a DLL. Not all that is gold glitters and not all who wander are lost (I don't know why that just came back to me).

But the basic question is whether VB6 has a mechanism for repositioning where in the input file you read from next. For example:
Article 1 is at 0 bytes
Article 2 is at 8779 bytes
Article 3 is at 17655 bytes
Article 4 is at 25565 bytes
Article 5 is at 40920 bytes
Article 6 is at 46897 bytes
Article 7 is at 54444 bytes
Article 8 is at 60997 bytes
Article 9 is at 68180 bytes
Article 10 is at 76314 bytes
Article 11 is at 82811 bytes
Article 12 is at 89321 bytes
Article 13 is at 93321 bytes
Article 14 is at 101121 bytes
...
Article 254 is at 2498603 bytes

First, how in VB6 can I even tell that Article 10 is positioned at 76,314 bytes? Second, how in VB6 would I go directly to 68180, then to 101121, then to 8779, etc? In C, you would use ftell() and fseek() respectively. What would you use in VB6?

Reply With Quote
  #4  
Old October 11th, 2003, 01:21 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,861 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 23 m 55 sec
Reputation Power: 462
I was about to give up on VB having basic file I/O support and to decide to get the real work done in a C DLL. That would have been a bummer, since part of the purpose of this exercise is to learn VB coding.

And I would have given up if I hadn't found an entry for "file pointer" in the index of O'Reilly's "VB & VBA in a Nutshell". VB's version of ftell is the SEEK function and of fseek is the SEEK statement. With that, I was finally able to find the right pages in the help files:
Quote:
Seek Function


Returns aLong specifying the current read/write position within a file opened using the Open statement.

Syntax

Seek(filenumber)

The required filenumberargument is anInteger containing a validfile number.

Remarks

Seek returns a value between 1 and 2,147,483,647 (equivalent to 2^31 – 1), inclusive.

----------------------------------
Seek Statement


Sets the position for the next read/write operation within a file opened using the Open statement.

Syntax

Seek [#]filenumber, position

The Seek statement syntax has these parts:

Part Description
filenumber Required. Any validfile number.
position Required. Number in the range 1 – 2,147,483,647, inclusive, that indicates where the next read/write operation should occur.

I also verified that the String data type is no longer limited to 255 characters, but rather can approach 64K.

Reply With Quote
  #5  
Old October 11th, 2003, 09:31 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
U will random access a file with vb,So u can use Get function:
Get [#]filenumber, [recnumber], varname
recnumber can be postion of the file...
U can find help in the vb help or MSDN...

Reply With Quote
  #6  
Old October 11th, 2003, 10:16 AM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
You shouldn't be using the old fiel I/O mech. anymore unless you are accessing binary files. You should be using the FileSystemObject and it's subsidory objects. This is on the 'Microsoft Scripting Run-time' or Scrrun.dll.

There is a TetStream object which acts as the I/O for text files, this has a ReadLine method and a Line property.

Have a look at the URL below.

http://support.microsoft.com/defaul...118&Product=vb6

Hope this helps

Dave

Reply With Quote
  #7  
Old October 11th, 2003, 12:00 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,861 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 23 m 55 sec
Reputation Power: 462
Quote:
Originally posted by cleverpig
U will random access a file with vb,So u can use Get function:
Get [#]filenumber, [recnumber], varname
recnumber can be postion of the file...
U can find help in the vb help or MSDN...

My understanding is that that only works with fixed-length records. I'd be dealing with variable-length records in which each "record" is either an article or a paragraph within that article (and, of course, there'd be a variable number of paragraphs per article).

Reply With Quote
  #8  
Old October 11th, 2003, 12:43 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,861 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 23 m 55 sec
Reputation Power: 462
Quote:
Originally posted by BanksySan
You shouldn't be using the old fiel I/O mech. anymore unless you are accessing binary files. You should be using the FileSystemObject and it's subsidory objects. This is on the 'Microsoft Scripting Run-time' or Scrrun.dll.

There is a TetStream object which acts as the I/O for text files, this has a ReadLine method and a Line property.

Have a look at the URL below.

http://support.microsoft.com/defaul...118&Product=vb6

Hope this helps

Dave

OK, I read that page which didn't tell me much except that I have to drag another run-time into the picture. And I Google'd and got lots of hits in lots of different languages saying how easy FileSystemObject. And I read the VB6 help file on FileSystemObject and TextStream. And I Google'd on "VB6 TextStream seek" and didn't get anything relevant.

So how am I supposed to do the equivalent of the SEEK function and statement when using TextStream? The closest thing to the SEEK function that I could find was the Line property, but I could not find any method for positioning to a specific line.

I kind of have this utilitarian attitude that, no matter how fashionable a feature is or how really easy it is to use, if it does not perform the required function then it is worthless. And what I am looking for is a fairly basic file I/O functionality.

Thank you for the information, but so far, I cannot see FSO or TextStream having any worth.

Reply With Quote
  #9  
Old October 11th, 2003, 01:25 PM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,840 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Days 36 m 16 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
Although the FSO does come in handy when dealing with typical file operations, for what you are wanting to do I believe you have found the best route with SEEK.

The FSO is good when it comes to dealing with directory dealing with with standard I/O file operations, but it is sometimes lacking when it comes to the more advanced sections like seek.

Reply With Quote
  #10  
Old October 11th, 2003, 01:32 PM
BanksySan's Avatar
BanksySan BanksySan is offline
A mule with a spinning wheel.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Wales
Posts: 113 BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level)BanksySan User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 48 m 39 sec
Reputation Power: 7
MySpace
I don't know how fasionable fso is, I haven't managed to pull any birds with it or get into any trendy clubs (though I haven't tried).

I haven't much experience of C and so may not have understood the SEEK method. It will take you directly to a line number in a text file.

TextStream has the SkipLine method. To skip back though the file needs to be explicitly closed and reopened.

I don't really have much experience of the old I/O though, so you are right, there may be a more intuative method using that.

I would emulate the SEEK method like this though:

Function Seek(Index As Integer,Ts as TextStream) as String

On Error Goto ErrorHandler 'In case a backwards index is given

Static OldIndex As Integer 'Last index called
Dim i As Integer 'Counter
Dim NumOfLinesToSkip As Integer

NumOfLineToSkip = Index - OldIndex

For i = 0 To NumOfLinesToSkip
Ts.SkipLine

Next i

Exit Function
ErrorHandler:

Err.Raise

End Function


I agree with onslaught in that it can be seriously frustrating at times

One, last thing, the strings in VB can be almost any size.

Reply With Quote
  #11  
Old October 12th, 2003, 01:37 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Hello,dwise1_aol !I think u maybe have the article length like you said:
Article 1 is at 0 bytes
Article 2 is at 8779 bytes
Article 3 is at 17655 bytes
Article 4 is at 25565 bytes
Article 5 is at 40920 bytes
Article 6 is at 46897 bytes
Article 7 is at 54444 bytes
Article 8 is at 60997 bytes
Article 9 is at 68180 bytes
Article 10 is at 76314 bytes
Article 11 is at 82811 bytes
Article 12 is at 89321 bytes
Article 13 is at 93321 bytes
Article 14 is at 101121 bytes
...
U can read one article by get function like it.
read article 1:
dim articlestr1 as string*8779
GET #1,0,articlestr1
read article 2:
dim articlestr2 as string*(17655-8779)
GET #1,8779,articlestr2....

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Newbisimo: VB6 File I/O Question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump