Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2007, 01:34 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default Correspondance -- or there abouts

I have opened a file using FileOpen, and i was wondering whether or not the Loc() function which returns current read/write position corresponds to the line its on, so if its on 4 then thats line 4??
Or have i got it completely wrong? if so how do i get data on a certain line??

Cheers,


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
__________________
Apocolypse2005, I'm a programmer - of sorts.
 
Old November 27th, 2007, 01:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It is documented here:

http://msdn2.microsoft.com/en-us/library/5tb5ex52(VS.80).aspx

You are correct though in your assumption, from the MSDN:
"Returns a Long value specifying the current read/write position within an open file."

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 27th, 2007, 02:27 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Sorry my brain is dead today, i still dont get how to get the line number
Is there someway of putting it into an array so:

Code:
Dim sLines() As String
Dim sCurrentLine As String
Dim iLineNum As Integer = 0

Do until EOF(1)
    sLine = LineInput(i)
    iLineNum = iLineNum + 1
Loop

sCurrentLine = sLine(iLineNum)
Cheers,

------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
 
Old November 27th, 2007, 02:40 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm, one of these pages might help you:
http://www.google.com/search?hl=en&s...s+in+text+file





================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 27th, 2007, 02:44 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

Oh, i know how to count the number lines in a file, but its just the line number im having trouble with but i think i have got it sorted!
What i've done is in the file i have put numbers at the front of each line obviously corresponding to the line number then i have just got code to loop (enumerate?) through and stop when it reachs the line i want!

Thanks all the same,


------------------------------------------------
Apocolypse2005
Always ready and waiting to be helped!
 
Old November 27th, 2007, 02:47 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ahhh i see. Glad you got it sorted out.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 27th, 2007, 05:10 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The way I would approach this is that I would start at the beginning of the file, and move through it 1 char at a time, tallying the characters that generate new lines.

(Of course, you cna do the same thing reading the file into a string and searching the string... mech less disc drive intensive, faster, smarter, etc.)









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.