Google Answers Logo
View Question
 
Q: Excel VB - Input Line with OSX text file ( No Answer,   3 Comments )
Question  
Subject: Excel VB - Input Line with OSX text file
Category: Computers > Programming
Asked by: les9999-ga
List Price: $10.00
Posted: 19 Apr 2005 14:27 PDT
Expires: 21 Apr 2005 22:04 PDT
Question ID: 511520
OS-X uses a different end of line character in text files than Windows
or OS-9. Because of this the input line command in Excel VB gets the
entire file rather than one line at a time. Is there a solution for
this?
Answer  
There is no answer at this time.

Comments  
Subject: Re: Excel VB - Input Line with OSX text file
From: justabum-ga on 21 Apr 2005 14:22 PDT
 
There are a few easy solutions to this. Here is one. 

1) Read in entire file as you are doing to one variable

2) Use the "split" function to convert the string to an array. I
believe the EOL marker in OS-X is chr(13); therefore your command will
look something like

myArray = split(myFile, chr(13))

3) loop through the array, each item being a line. i.e.

for i = 0 to ubound(myArray)
process(myArray(i))
next
Subject: Re: Excel VB - Input Line with OSX text file
From: les9999-ga on 21 Apr 2005 15:15 PDT
 
When trying this approach I get the message compile error "Can't
assign to array". My code looks like:

dim myarray(1 to 3000) as string
dim myfile as string
open "file.txt" for input as #1
input line #1, myfile
myarray = split(myfile,chr(13))
...
...
Any additional suggestions?

Thanks,
Subject: Re: Excel VB - Input Line with OSX text file
From: les9999-ga on 21 Apr 2005 22:04 PDT
 
I see how it works now. You can't specify the array limit.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy