Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WRQ Reflections VBA help - Importing a text file 1

Status
Not open for further replies.

JWishbone

Technical User
May 1, 2006
3
US
To all,

I am a programming novice who needs some help importing a multi-line text file and outputting it. The text file looks like this:

LIST CAR-INV WITH STATUS EQ "S" AND WITH I-ACCT NE
"12345""23456""34567""45678""56789""98765""87654""76543""65432"""
DAYS COLOR I-ACCT MAKE MILES MODEL MODEL-NO. MODEL-YEAR SLIST
SERIAL STANDARD_BODY STANDARD_COLOR STICKER STOCK-NO. STOCK-TYPE
ID-SUPP NOPAGE SUPP


I need to take in each line and write it out as a terminal command. I am okay with writing commands to the terminal, but I am having alot of difficulty importing the text file and getting each line in to it's own string. What I have so far looks like this:


Dim DownloadDir As String
Dim ENGStatementFile As String
Dim Import As String


DownloadDir = "D:\download\"
ENGStatementFile = "statement.eng"


Set ENGStatement = GetObject("Scripting.FileSystemObject")
Set Action = GetObject(DownloadDir & ENGStatementFile, True)
Action.ReadAll = Import
Action.Close


On Error GoTo 0


With Session
.Transmit Import


I'm sure that this is the wrong way to do it, but this is way more advanced than I have ever needed to make a VBA macro. I can add a delimiter to the end of each line if needed, like a semi-colon, but I was hoping that it could be done without one. Any help would be greatly appreciated.
 
Would the <object>.ReadLine method work for you?

_________________
Bob Rashkin
 
I'm game for whatever will work. How would I get it to read each line? There are 4 lines in the text file. I saw <object>.ReadLine in the VBA help, but there were no examples and I don't understand how it works. How do I tell it to read in each line?

Here is all that was in the help file:

Description
Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.
Syntax
object.ReadLine
The object argument is always the name of a TextStream object.


Can you loop it for each line like this:

Dim x As Integer
x = 4
Do
Action.ReadLine(x) = Import(x)
x = (x - 1)
Loop Until x = 0
 
Perhaps something like:
Do While a.AtEndOfStream <> True
retstring = a.ReadLine
...
Loop
(this is from the VBA Help file)

Where "a" is "Action" in your case.

_________________
Bob Rashkin
 
After some more tweaking, that works just perfectly. Thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top