• 2 replies
  • Latest Post - ‏2013-07-16T20:32:15Z by llandale
19 Posts

Pinned topic expected int attribute

‏2013-07-08T22:46:25Z |

I have a module with a 'PER' attribute that is numbered sequentially according to another 'ER' attribute.  So I created this for loop which numbers it perfectly in one module and then gives me an error on the last line during another.


Object o
string ER
string PER = "PER"
int count_5 = 0

for o in current do {

ER = o."ER"

if ER == "5ms" then {
o.PER = count_5



When it gets to the last line: o.PER = count_5 it halts the execution and says "expected int attribute."  I've found out that in one module the attribute, PER, is defined as text while the other defines it as an integer.  Is there a way to check the value and define it accordingly?

if AttrBaseType==attrText then

o.PER = "count_5" else

o.PER = count_5

I can't figure out the integer to string conversion.

Updated on 2013-07-08T23:13:48Z at 2013-07-08T23:13:48Z by stevenson
  • MichaelGeorg
    53 Posts

    Re: expected int attribute


    Hello Stevenson,

    converting a integer to string can be done by simply putting double quotes (  ""  ) behind it.

    So in your case that would be:

    o.PER = count_5 ""

    Actually assigning a string (which contains only numbers) to a integer works quite well. So you don't even need to check for the attribute type but can just use above statement regardless of the attribute's type.

     - Michael

  • llandale
    3035 Posts

    Re: expected int attribute


    To clarify Mike, you CAN assign a "string" to an "int" attribute so long as the string looks like an integer.  Thus, you can turn your int into a string and this line should work for both modules:

    • o.PER = count_5 ""

    You cannot do the opposite, put an "int" into a "string" attr, as you found out.

    Seems to me though you have a project admin problem if you have the same attribute defined diffferently in more than one module.  You <<should>> fix the rouge module.

    • create(object type int attribute "PER_Temp")
    • for o in entire m do
    • {  if (!isDeleted(o)) then o."PER_Temp" = o."PER" ""
    • }
    • delete attribute "PER" but I forget syntax
    • modify name of "PER_Temp" to "PER" but I forget syntax

    Actually it is better to turn off History for "PER_Temp" while copying, and turn it back on afterwards in order to suppress History "23 = 23" which provides no value.

    or just delete PER and recreat it type "int", and run your original script to populate it.


    BTW, in your original when "ER" is not "5ms" do you not want to erase "PER"?