Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
edauthier
- Pro Scripter
- Posts: 84
- Joined: Sun Apr 13, 2003 1:26 pm
- Location: USA
Post
by edauthier » Thu Aug 23, 2007 12:31 am
Does anyone have code for counting the number of times you've looped in a script until you've reached ##EOF##? Not reading the values, but the loops thru until all the lines are accounted for?
Code: Select all
Let>k=1
Label>start
ReadLn>c:\temp\test.txt,k,line
If>line=##EOF##,finish
Message>line
Let>k=k+1
Goto>start
Label>finish
-
edauthier
- Pro Scripter
- Posts: 84
- Joined: Sun Apr 13, 2003 1:26 pm
- Location: USA
Post
by edauthier » Thu Aug 23, 2007 1:04 am
Posted my question a little too early, actually found an old vb script of mine that I can tie in. I tested, works nicely.
But if you have straight Macro commands I would appreciate you posting iust the same.
BTW if you change:
Lines = (cstr(ubound(acontents)))+1 to
Lines = strcontents
it will return the values in your file.
Take Care, Ed
Code: Select all
VBSTART
Function Lines
const filename="c:\1\data.txt"
set fso=createobject("scripting.filesystemobject")
set ofile=fso.opentextfile(filename)
strcontents=ofile.readall
ofile.close
set ofile=nothing
set fso=nothing
acontents=split(strcontents,vbcrlf)
'wscript.echo "LOCATION : " & cstr(ubound(acontents)+1)
Lines = (cstr(ubound(acontents)))+1
End Function
VBEND
VBEval>Lines,line_info
MessageModal>line_info
-
pgriffin
- Automation Wizard
- Posts: 460
- Joined: Wed Apr 06, 2005 5:56 pm
- Location: US and Europe
Post
by pgriffin » Thu Aug 23, 2007 2:23 am
You have your own answer in your first post. The number of loops through your file until EOF will be contained in the variable k.
No VBScript required.
-
edauthier
- Pro Scripter
- Posts: 84
- Joined: Sun Apr 13, 2003 1:26 pm
- Location: USA
Post
by edauthier » Thu Aug 23, 2007 3:29 am
Thanks Paul,
Actually, the k return will always give you +1 in the return value. Which (as you noted) is the number of loops. However, the VB Script will return exact number of entries in the text file, which I was really trying to achieve.
Thnaks again.
-
pgriffin
- Automation Wizard
- Posts: 460
- Joined: Wed Apr 06, 2005 5:56 pm
- Location: US and Europe
Post
by pgriffin » Thu Aug 23, 2007 3:30 am
ok, so K-1 should do the trick. Still VBScript is not required for counting records.
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Thu Aug 23, 2007 4:02 am
Actually, if you put the "Let>k=k+1" at the top of the code you won't even need to subtract to have k=the exact number of lines
Let>k=0
Label>start
Let>k=k+1
ReadLn>c:\temp\test.txt,k,line
If>line=##EOF##,finish
Message>line
Goto>start
Label>finish
-
edauthier
- Pro Scripter
- Posts: 84
- Joined: Sun Apr 13, 2003 1:26 pm
- Location: USA
Post
by edauthier » Thu Aug 23, 2007 4:09 am
Yeah, the original post is straight from the help file.