How Arraycount after CSVFileToArray

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
olllllliii
Pro Scripter
Posts: 60
Joined: Tue Dec 22, 2009 9:51 am
Location: Mannheim ( Germany )
Contact:

How Arraycount after CSVFileToArray

Post by olllllliii » Fri Nov 30, 2012 2:26 pm

// read a CSV works perfect
// To see whats inside the file ( its no secrect its my pricelist )
// ->>>>> http://www.ohilger.de/eue.csv


CSVFileToArray>C:\Users\username\Desktop\eue.csv,arrCSV

// i can read all dimensions of the array like
// Let>info=arrCSV_1_1
// MDL>info

// but if i want to count the Elements of the array it always say
//

ArrayCount>arrCSV,Numinfo
MDL>Numinfo

// What is wrong with me and my script ....??
Oliver Hilger Mannheim
alias Olllllliii

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 30, 2012 4:55 pm

Nothing wrong with you. ArrayCount can only work with single dimension arrays. CSV files are multi-dimensional.

ArrayCount can work with ONE of the dimensions.

The first dimension of the array produced by CSVFileToArray is the row. You could use ArrayCount on that to see how many fields there in the row:

ArrayCount>arrCSV_1

But you don't need to. CSVFileToArray returns a count for each row (each dimension) and also the total number of rows anyway.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

olllllliii
Pro Scripter
Posts: 60
Joined: Tue Dec 22, 2009 9:51 am
Location: Mannheim ( Germany )
Contact:

Post by olllllliii » Fri Nov 30, 2012 9:18 pm

Thank you Marcus ,

so i wrote a small script to get the lines of the data .
Here is the solution. It is much faster than the old version ..

// The old version is very slow on big files

Let>count=0
Let>filename=c:\daten4.txt
Label>Start
Let>count=count+1
ReadLn>filename,count,line
If>line=##EOF##,end
Goto>Start
Label>end
MessageModal>Number of lines in file = %count%

// end old version

// Very much faster to count lines

Code: Select all

Let>count=1
Let>filename=C:\Users\Steffen\Desktop\eue.csv

CSVFileToArray>filename,arrCSV

Label>Start
Let>count=count+1
Let>data=arrCSV_%count%_1
Midstr>data,1,6,out
If>out={"arrCSV"},end
Goto>Start
Label>end
MessageModal>you have %count% lines in your file
Kind regards
Oliver
Oliver Hilger Mannheim
alias Olllllliii

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Sat Dec 01, 2012 9:56 pm

Hi olllllliii,

Thanks for sharing your solution. I wonder if that is the fastest way possible to find the number of lines in a file?

If anyone has another way they think might be faster, please post and share it with us all.

Your post reminded me of a similar problem I had only I had to very quickly count the number of lines pasted into a memo field on a dialog in a compiled MS script. Check out the link below and maybe you can make use of the techniques there as well:

[Bounty Won] Text Blob Line Counter Speed Challenge
http://www.mjtnet.com/forum/post23762.html#23762

Take care
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Dec 02, 2012 1:59 am

jpuziano wrote:Hi olllllliii,

Thanks for sharing your solution. I wonder if that is the fastest way possible to find the number of lines in a file?

If anyone has another way they think might be faster, please post and share it with us all.


Your post reminded me of a similar problem I had only I had to very quickly count the number of lines pasted into a memo field on a dialog in a compiled MS script. Check out the link below and maybe you can make use of the techniques there as well:

[Bounty Won] Text Blob Line Counter Speed Challenge
http://www.mjtnet.com/forum/post23762.html#23762

Take care
Here are 2 quick methods to count files, one uses Separate the other uses ReadLn. You be the judge.

Code: Select all

DEL>%TEMP_DIR%MS Test Text Document.txt
EXP>MS_TEST_TEXT_DOCUMENT.TXT_DATA,%TEMP_DIR%MS Test Text Document.txt
//Method 1
Timer>StartTimer
ReadFile>%TEMP_DIR%MS Test Text Document.txt,Lines
Separate>Lines,CRLF,NumLines
Timer>EndTimer
LET>ElapsedTime={(%EndTimer%-%StartTimer%)/1000}
Let>Method1=Lines: %NumLines_count%%CRLF%Time: %ElapsedTime% sec

//Method 2
Let>k=0
Timer>StartTimer
Repeat>k
  Add>k,1
  ReadLn>%TEMP_DIR%MS Test Text Document.txt,k,res
  If>res=##EOF##
  Sub>k,1
  Goto>Done
  ENDIF
Until>k,0

Label>Done
Timer>EndTimer
LET>ElapsedTime={(%EndTimer%-%StartTimer%)/1000}
DEL>%TEMP_DIR%MS Test Text Document.txt
Let>Method2=Lines: %k%%CRLF%Time: %ElapsedTime% sec
mdl>Method 1 Result:%CRLF%%Method1%%CRLF%Method 2 Result:%CRLF%%Method2%



/*
MS_TEST_TEXT_DOCUMENT.TXT_DATA:
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A
310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310
D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A310D0A31
*/

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1389
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Wed Jan 23, 2013 1:35 am

olllllliii wrote:Thank you Marcus ,

so i wrote a small script to get the lines of the data .
Here is the solution. It is much faster than the old version ..

// The old version is very slow on big files

Let>count=0
Let>filename=c:\daten4.txt
Label>Start
Let>count=count+1
ReadLn>filename,count,line
If>line=##EOF##,end
Goto>Start
Label>end
MessageModal>Number of lines in file = %count%

// end old version

// Very much faster to count lines

Code: Select all

Let>count=1
Let>filename=C:\Users\Steffen\Desktop\eue.csv

CSVFileToArray>filename,arrCSV

Label>Start
Let>count=count+1
Let>data=arrCSV_%count%_1
Midstr>data,1,6,out
If>out={"arrCSV"},end
Goto>Start
Label>end
MessageModal>you have %count% lines in your file
Kind regards
Oliver
Ollie,

I used this multiple times today. Just wanted to say thank you. I think you may see it somewhere else soon... shh... secret.
Yes, we have a Custom Scripting Service. Message me or go here

olllllliii
Pro Scripter
Posts: 60
Joined: Tue Dec 22, 2009 9:51 am
Location: Mannheim ( Germany )
Contact:

Re: How Arraycount after CSVFileToArray

Post by olllllliii » Wed Oct 14, 2020 10:41 am

The Final Linecount Programm ...much faster

Let>strDatei=C:\Users\Olllllliii\Desktop\yourfile.csv
ReadFile>strDatei,strData

Let>muster=CRLF
Regex>muster,strData,1,ArrZ,numArr,0,,
Let>info=numArr
MDL>info

This script is many times faster than the older ones
Oliver Hilger Mannheim
alias Olllllliii

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts