From: Gadgetman on
I have the following code:

Do Until objInput.AtEndOfStream
strLine = objInput.ReadLine
' Skip blank lines.
If (Trim(strLine) <> "") Then
' Parse the fields in the file.
arrValues = CSVParse(strLine) 'Copyright (c) 2007 Richard L. Mueller
Hilltop Lab web site - http://www.rlmueller.net
' Set variables for each field read from file.
strCount = strCount +1
strFirst = arrValues(0)
strSecond = arrValues(1)
strThird = arrValues(2)
strFourth = arrValues(3)
Set objCFile = objFSO.OpenTextFile("File2.txt", ForReading)
' Next part should read from text csv file that contains two fields - first
field is a list of values that will equal strFourth from First file
Do Until objCFile.AtEndOfStream
strCline = objCFile.Readline
arrFields = Split(strCLine, ",")
strChars = arrFields(0)
If strFourth = strChars Then strNCount = arrFields(1)
'Else
'End If
Loop
objCFile.Close

objOutput.WriteLine strCount & "," & strFirst & "," & strSecond & "," &
strThird & "," strFourth & "," strNCount

What I am attempting to do is open a file that contains a number of fields:
First, Second, Third and Fourth. For example it may contain the following
two rows:
Apple, Banana, Carrot, Donut
Egg, Fruit, Goat, Hair
I have a second file that contains two fields: Chars and NCount. For example:
Donut, 3
Hair, 1

What I am trying to do is output to a file that contains the following lines:
1, Apple, Banana, Carrot, Donut, 3
2, Egg, Fruit, Goat, Hair, 1

The code does not return the 3 but returns a blank, but does return the 1.

I know that it has to be something simple but I just can't seem to see it.
Any assistance is greatly appreciated.
From: Al Dunbar on


"Gadgetman" <Gadgetman(a)discussions.microsoft.com> wrote in message
news:02FC6EE3-98E1-4DBE-B78D-A4813BCD1E9C(a)microsoft.com...
> I have the following code:
>
> Do Until objInput.AtEndOfStream
> strLine = objInput.ReadLine
> ' Skip blank lines.
> If (Trim(strLine) <> "") Then
> ' Parse the fields in the file.
> arrValues = CSVParse(strLine) 'Copyright (c) 2007 Richard L. Mueller
> Hilltop Lab web site - http://www.rlmueller.net

I'm not sure if Richard actually holds the copyright on that particular
statement, but I suspect he would prefer that his copyright notice not be
attached to a non-functional script! ;-)

> ' Set variables for each field read from file.
> strCount = strCount +1
> strFirst = arrValues(0)
> strSecond = arrValues(1)
> strThird = arrValues(2)
> strFourth = arrValues(3)

> Set objCFile = objFSO.OpenTextFile("File2.txt", ForReading)
> ' Next part should read from text csv file that contains two fields -
> first
> field is a list of values that will equal strFourth from First file
> Do Until objCFile.AtEndOfStream
> strCline = objCFile.Readline
> arrFields = Split(strCLine, ",")
> strChars = arrFields(0)
> If strFourth = strChars Then strNCount = arrFields(1)
> 'Else
> 'End If
> Loop

Your code will read file2.txt a number of times. I'd suggest you read it
once before the outer loop starts and modify the above to operate on the
data previously read in.

> objCFile.Close
>
> objOutput.WriteLine strCount & "," & strFirst & "," & strSecond & "," &
> strThird & "," strFourth & "," strNCount
>
> What I am attempting to do is open a file that contains a number of
> fields:
> First, Second, Third and Fourth. For example it may contain the following
> two rows:
> Apple, Banana, Carrot, Donut
> Egg, Fruit, Goat, Hair
> I have a second file that contains two fields: Chars and NCount. For
> example:
> Donut, 3
> Hair, 1
>
> What I am trying to do is output to a file that contains the following
> lines:
> 1, Apple, Banana, Carrot, Donut, 3
> 2, Egg, Fruit, Goat, Hair, 1

well, first thing, the writeline statement on its own will only write out
one line not two. you will probably need to move it within the loop that
processes successive lines of the first file.

> The code does not return the 3 but returns a blank, but does return the 1.

rather than describing the result differentially, try showing us exactly
what the script output is. While you're at it, you should also show an exact
copy of the script.

/Al


>
> I know that it has to be something simple but I just can't seem to see it.
> Any assistance is greatly appreciated.