counting rows and unique numbers

Discuss RoboTask here
Post Reply
jeroen123
Posts: 25
Joined: Wed Feb 15, 2012 5:35 pm

counting rows and unique numbers

Post by jeroen123 »

Hello Oleg,

I have a simple tekst file of numbers (customerIDnumbers) like:
1225
1225
1309
1388
1388
2820
2820

I want to know how many lines I have; and how many unique numbers; in this case 7 rows, and 4 unique numbers.

so I wrote the following script:
with a íf' statement to compare the customerIDnumber with a 'compare' value.
It seems that this doesnot work; it shows the new value already in step 7 where it should only change in step 11..?
have you got a hint for me?

Thanks!
Jeroen

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|0
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task9"
Hide=INTEGER|0
ID=INTEGER|461530805
LogOnAsUser=INTEGER|1
Name=STRING|"COUNT ROWS AND DIFFERENT CUSTOMERS"
OnErrorTaskID=INTEGER|0
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""ROWS"" with value ""0"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
varname=STRING|"ROWS"
varvalue=STRING|"0"

[Actions\Action10]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action11]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""COMPARE"" with value ""{CUSTNO}"""
Params=FOLDER

[Actions\Action11\Params]
expand=STRING|"0"
varname=STRING|"COMPARE"
varvalue=STRING|"{CUSTNO}"

[Actions\Action12]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""COMPARE"" with value ""0"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
varname=STRING|"COMPARE"
varvalue=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CUST"" with value ""0"""
Params=FOLDER

[Actions\Action3\Params]
expand=STRING|"0"
varname=STRING|"CUST"
varvalue=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""CUSTNO"" with value ""0"""
Params=FOLDER

[Actions\Action4\Params]
expand=STRING|"0"
varname=STRING|"CUSTNO"
varvalue=STRING|"0"

[Actions\Action5]
ActionID=STRING|"A_LOOP_TEXT"
Enabled=INTEGER|-1
Name=STRING|"Text Loop"
Params=FOLDER

[Actions\Action5\Params]
destvar=STRING|"CUSTNO"
line0=STRING|"1225"
line1=STRING|"1225"
line2=STRING|"1309"
line3=STRING|"1388"
line4=STRING|"1388"
line5=STRING|"2820"
line6=STRING|"2820"
linecount=STRING|"7"
sourcetext=STRING|"1"

[Actions\Action6]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""ROWS"""
Params=FOLDER

[Actions\Action6\Params]
incement=STRING|"1"
vaiable=STRING|"ROWS"

[Actions\Action7]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""ROWS: {ROWS}"""
Params=FOLDER

[Actions\Action7\Params]
icon=STRING|"1"
msg0=STRING|"ROWS: {ROWS}"
msg1=STRING|"CUSTNO: {CUSTNO}"
msg2=STRING|"COMPARE: {COMPARE}"
msg3=STRING|"CUST: {CUST}"
msgcount=STRING|"4"
playsound=STRING|"0"
showmessage=STRING|"1"

[Actions\Action8]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action8\Params]
case=STRING|"0"
operator=STRING|"1"
type=STRING|"1"
value1=STRING|"{CUSTNO}"
value2=STRING|"{COMPARE}"

[Actions\Action9]
ActionID=STRING|"A_VARIABLES_INCREMENT"
Enabled=INTEGER|-1
Name=STRING|"Increment variable ""CUST"""
Params=FOLDER

[Actions\Action9\Params]
incement=STRING|"1"
vaiable=STRING|"CUST"
Oleg
Site Admin
Posts: 3202
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: counting rows and unique numbers

Post by Oleg »

You should turn ON "Expand variable now" parameter
expandnow.png
expandnow.png (44.43 KiB) Viewed 11490 times
If it is OFF then you set the value "{CustNo}" (not a number)
in step #8 RoboTask expands the expression "{COMPARE}" and gets "{CustNo}". Expands again and gets the same number as in CustNo variable

If it is ON then RoboTask expand the expression first and then assigns the result into variable.

Also, pay attention that this algorithm works only for sorted lists
Oleg Yershov
jeroen123
Posts: 25
Joined: Wed Feb 15, 2012 5:35 pm

Re: counting rows and unique numbers

Post by jeroen123 »

Thanks!, this works :D
Post Reply