increment a variable

1,271 views
Skip to first unread message

Cha malo

unread,
Sep 30, 2016, 9:23:37 AM9/30/16
to robotframework-users
Hi,
I've found some result on google about my problem, but none of them solved my issue. I'm trying to count the number of occurence of 5 item (1 2 3 4 5) in a list:
   ${num0} =    Convert To Number    0
    ${num1} =    Convert To Number    0
    ${num2} =    Convert To Number    0
    ${num3} =    Convert To Number    0
    ${num4} =    Convert To Number    0
    ${num5} =    Convert To Number    0
    :FOR    ${index}    IN RANGE    0    ${vcanum}
    \    ${num0} =    Evaluate    ${num0} + 1
    \    ${num1} =    Run Keyword If    @{elementtext}[${index}] == 1    Evaluate    ${num1} + 1
    \    ${num2} =    Run Keyword If    @{elementtext}[${index}] == 2    Evaluate    ${num2} + 1
    \    ${num3} =    Run Keyword If    @{elementtext}[${index}] == 3    Evaluate    ${num3} + 1
    \    ${num4} =    Run Keyword If    @{elementtext}[${index}] == 4    Evaluate    ${num4} + 1
    \    ${num5} =    Run Keyword If    @{elementtext}[${index}] == 5    Evaluate    ${num5} + 1

 \    ${num0} =    Evaluate    ${num0} + 1: this line is incremented every time.

But the others, i've an error:
Evaluating expression 'None + 1' failed: TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Tatu Aalto

unread,
Sep 30, 2016, 10:41:57 AM9/30/16
to Cha malo, robotframework-users

Ugh

I would assume that for loop works for the first iteration, but it fails on the second iteration. This is because in the first iteration, the number in the ${num*} variables is set to None when the expression in Run Keyword If keyword evaluates as false. When the expression is evaluated as False the Run Keyword If doesn't have anything to return because Evaluate keyword is not run and therefore None is saved to the ${num*} variables.

There is way to solve your problem in the example by using Set Variable If[1] keyword. But perhaps we could find a better solution to your problem if you could explain what is the problem you are trying to solve.

-Tatu
Send from my mobile
[1] http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Set%20Variable%20If


--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages