Hello,

I'm working on a program that needs to parse a text file, pulling out
a field and it's corresponding value. The fields I need to search for
are in a text file, one field per line. All of this is really simple
and straightforward to me, but I cannot figure out why my output (to
the console) is not what I expect.

Below is the portion of my code that is of interest and below that is
the output I'm getting.

So that you do not have to guess at what I'm talking about. Let me
point out the line:

out.Write(trim(tmp) & "e")

But the output that I get is: "e4"

There should be an "A" where the "e" is and the "e" should be AFTER
the "4".

Thanks for the help!


********CODE***********

Set out = Wscript.StdOut

' Read in fields
out.Write("Reading fields... ")
set txt = fs.OpenTextFile(cfgFieldsFile,1)
aryFields = trim(txt.ReadAll)
txt.Close

aryFields = split(aryFields,chr(10))
out.WriteLine((Ubound(aryFields)+1) & " fields found")

If dbgShowFields Then
For Each tmp in aryFields
out.Write(trim(tmp) & "e")
out.WriteBlankLines(1)
Next
End If

aryFields = join(aryFields," ")
out.writeline("start " & aryFields & " end")
out.writeline(len(aryFields))


**********OUTPUT**************

Reading fields... 30 fields found
e4
eSTG3
eell
eode
e3d2fb
e44d4
e5d45
esn
e
e2fb
e3qp2
ebar
ecell
ecfb
e3fb
edg
ehp
ehpmr1
ehpr1
e2
e3f
e5m
edate
ehpg1
ear0
efkrk
etime
egturn
enf
xnge

Re: stdout.writeline output issue by ibeanon

ibeanon
Sun Mar 23 22:29:19 CDT 2008

Some more information...

When I change the the foreach loop to:

If dbgShowFields Then
For Each tmp in aryFields
out.WriteLine(trim(tmp))
out.writeline(len(tmp))
Next
End If

This is the following output. Which is something else that does not
make sense to me, since, as far as I can tell, there are not hidden
characters or anything.

Reading fields... 30 fields found
A4
3
ASTG3
6
Cell
5
Code
5
E3d2fb
7

Re: stdout.writeline output issue by Tim

Tim
Mon Mar 24 00:10:48 CDT 2008

Perhaps your file's lines are not delimted by Chr(10) but by Chr(10)+Chr(13)
?

Tim


<ibeanon@gmail.com> wrote in message
news:763943ee-755d-45a1-b5ca-faa129396503@q78g2000hsh.googlegroups.com...
> Some more information...
>
> When I change the the foreach loop to:
>
> If dbgShowFields Then
> For Each tmp in aryFields
> out.WriteLine(trim(tmp))
> out.writeline(len(tmp))
> Next
> End If
>
> This is the following output. Which is something else that does not
> make sense to me, since, as far as I can tell, there are not hidden
> characters or anything.
>
> Reading fields... 30 fields found
> A4
> 3
> ASTG3
> 6
> Cell
> 5
> Code
> 5
> E3d2fb
> 7



Re: stdout.writeline output issue by Todd

Todd
Mon Mar 24 00:43:30 CDT 2008

ibeanon@gmail.com wrote:
> Hello,
>
> I'm working on a program that needs to parse a text file, pulling out
> a field and it's corresponding value. The fields I need to search for
> are in a text file, one field per line. All of this is really simple
> and straightforward to me, but I cannot figure out why my output (to
> the console) is not what I expect.
>
> Below is the portion of my code that is of interest and below that is
> the output I'm getting.
>
> So that you do not have to guess at what I'm talking about. Let me
> point out the line:
>
> out.Write(trim(tmp) & "e")
>
> But the output that I get is: "e4"
>
> There should be an "A" where the "e" is and the "e" should be AFTER
> the "4".
>
> Thanks for the help!
>
>
> ********CODE***********
>
> Set out = Wscript.StdOut
>
> ' Read in fields
> out.Write("Reading fields... ")
> set txt = fs.OpenTextFile(cfgFieldsFile,1)
> aryFields = trim(txt.ReadAll)
> txt.Close
>
> aryFields = split(aryFields,chr(10))

Replace chr(10) with vbcrlf

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)


Re: stdout.writeline output issue by Pegasus

Pegasus
Mon Mar 24 04:39:32 CDT 2008


<ibeanon@gmail.com> wrote in message
news:87a6dfdd-b816-4ad1-b6cc-f985fc50bb47@e39g2000hsf.googlegroups.com...
> Hello,
>
> I'm working on a program that needs to parse a text file, pulling out
> a field and it's corresponding value. The fields I need to search for
> are in a text file, one field per line. All of this is really simple
> and straightforward to me, but I cannot figure out why my output (to
> the console) is not what I expect.
>
> Below is the portion of my code that is of interest and below that is
> the output I'm getting.
>
> So that you do not have to guess at what I'm talking about. Let me
> point out the line:
>
> out.Write(trim(tmp) & "e")
>
> But the output that I get is: "e4"
>
> There should be an "A" where the "e" is and the "e" should be AFTER
> the "4".
>
> Thanks for the help!
>
>
> ********CODE***********
>
> Set out = Wscript.StdOut
>
> ' Read in fields
> out.Write("Reading fields... ")
> set txt = fs.OpenTextFile(cfgFieldsFile,1)
> aryFields = trim(txt.ReadAll)
> txt.Close
>
> aryFields = split(aryFields,chr(10))
> out.WriteLine((Ubound(aryFields)+1) & " fields found")
>
> If dbgShowFields Then
> For Each tmp in aryFields
> out.Write(trim(tmp) & "e")
> out.WriteBlankLines(1)
> Next
> End If
>
> aryFields = join(aryFields," ")
> out.writeline("start " & aryFields & " end")
> out.writeline(len(aryFields))
>

You can easily resolve these problems by examining the problem
string in detail, e.g. like so:

str = ""
For i = 1 To Len(tmp)
str = str & Asc(Mid(tmp, i, 1)) & " "
Next
wscript.echo str

You would immediately notice that the string "tmp" is terminated
by $0d (carriage return), which others in this thread have also
suggested. This is what's causing your problem.



Re: stdout.writeline output issue by Todd

Todd
Mon Mar 24 16:39:22 CDT 2008

Pegasus (MVP) wrote:
> <ibeanon@gmail.com> wrote:
> > ... I cannot figure out why my output (to
> > the console) is not what I expect.
...

> You can easily resolve these problems by examining the problem
> string in detail, e.g. like so:
>
> str = ""
> For i = 1 To Len(tmp)
> str = str & Asc(Mid(tmp, i, 1)) & " "
> Next
> wscript.echo str
>
> You would immediately notice that the string "tmp" is terminated
> by $0d (carriage return), which others in this thread have also
> suggested. This is what's causing your problem.

Good idea. I forgot to mention, the output OP sees is only seen when output
is sent to console because CR without the LF causes output on screen to
overwrite itself. If redirected to a file and then viewed with a text
editor, the output can be seen differently.

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)