Hi, nice questions. I need to explore more to answer these questions but to
start with.. you got to know that OPEN statement supports below five modes.

Mode

*File** type*

Action

INPUT

Sequential

Read from

OUTPUT

Sequential

Write to

APPEND

Sequential

Append to

BINARY

Binary

Reading or writing

RANDOM

Random

Reading or writing (default)

And you can use the  RANDOM mode of the open statement to get the answer for
your question 2. I am not sure about the millionth line but you should be
able to read random lines like 4th line, 20th line etc., try using    Open
"filename.txt" For Random As #1 Len = 20
'Len depends on your file. This is the record length
       Get #1, 4, tempstring
I didn't test the above just wrote what I remember from my previous
experiments.
Hope this helps.

On Fri, May 22, 2009 at 1:26 PM, howard.lawren...@gmail.com <
howard.lawren...@gmail.com> wrote:

>
> Hi everyone,
> Thank you for reading my questions. I look forward to your responses.
>
> I am reading in data from a text file. For simplicity's sake, let's
> say
> I'm using the following code:
>
> Sub ProgramName()
>    Open "filename.txt" For Input As #1
>    for i=1 to 10
>        Line Input #1, tempstring
>        Range("a1").offset(i-1,0).Value = tempstring
>    Next i
>    Close #1
> End Sub
>
> Question #1: Let's say that after reading in 10 lines, I decide that I
> want to read them in again. In other words, I'd like the next "Line
> Input #1, tempstring" command to start over at the beginning. Is there
> a way to do it without closing and reopening file #1?
>
> Question #2: (related) Is there a way to randomly access a line from a
> text file? That is, let's say that I know I want the read the
> millionth line from filename.txt above. Can I do it without reading in
> every line before it?
>
> Question #3: (unrelated) When I was using Excel 2000 with an XP
> operating system, I had no trouble breaking out of VBA code while it
> was running. Ctl-Break seemed to do the trick every time. Now, with
> Excel 2007 with Vista, the Ctl-Break doesn't work as well. Sure, it
> will send me into break mode if it's a very modest program (a simple
> but lengthy loop), but if the code gets complicated at all, forget it.
> It simply won't break. Does anybody know a what I can do?
>
> Thank you again,
> Howard
>
> >
>


-- 
http://funwithexcel.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to