Topic
  • 5 replies
  • Latest Post - ‏2019-05-28T13:15:54Z by Christopher Cote
Christopher Cote
Christopher Cote
67 Posts

Pinned topic Trouble getting attribute value from object

‏2019-05-24T14:20:12Z |

I'm sure I've done this before, but I'm getting an error now when I try to check the value of an object's attribute, I am getting an error with my code:

currMod = read(modName)
for o in currMod do {
    for attribName is skAttrs do {
        if (o.attribName "" != "") {
            find(skAttrs, attribName, numAttr);
            delete(skAttrs, attribName);
            numAttr++;
            put(skAttrs, attribName, numAttr);
        }
    }
}

The error I'm getting is on line 3 of this block of code.  The error says "null string parameter was passed into argument position 2".  Above this for-loop, I have another for-loop that sets up the skAttrs skip list for all the attributes:

for ad in currMod do {
    if (!ad.system) {
        attribName = ad.name"";
        put(skAttrs, attribName, 0);
    }
}

This error isn't making any sense to me.  Please help this intermediate DXL coder.

 

Chris

  • Mike.Scharnow
    Mike.Scharnow
    586 Posts
    ACCEPTED ANSWER

    Re: Trouble getting attribute value from object

    ‏2019-05-25T09:43:04Z  

    First of all, I apologize for the extra post with the same question.  Somehow I didn't think my browser was working and I hit Save again.  I figured out how to get the attribute name from the skip list, but now I want to find out if the current object's attribute is blank.  I now have the following code:

    for obj in currMod do {
        for o in skAttrs do {
            attribName = (string key skAttrs);
            if (obj.attribName != "") {
                //Get the number saved in skAttrs for this attribute to increment it.
            }
        }
    }
    

    However, I get an error on the if-statement, which I'm pretty sure is because the code is trying to find an attribute called attribName instead of the value in attribName.  Sorry if I didn't make that clear originally.

     

    Chris

    try

    if (obj.attribName"" != "")
    

    i.e. don't "compare an AttrRef_ against a string" but "convert an attribute to a string, i.e. extract the value of a string attribute and compare the value against another string"

  • davidcs
    davidcs
    71 Posts

    Re: Trouble getting attribute value from object

    ‏2019-05-24T15:52:01Z  

    It looks like you are storing the value of the skiplist as a integer, and then loop through it expecting a string. So do something like this instead:

     

    for ad in currMod do {
        if (!ad.system) {
            attribName = ad.name"";
            put(skAttrs, attribName, attribName);
        }
    }
    

     

  • llandale
    llandale
    3088 Posts

    Re: Trouble getting attribute value from object

    ‏2019-05-24T18:04:04Z  

    the "for variable in SKIP" loop returns the DATA of the Skip, not the "KEY".  In this case you are "put"ting a type "int" (the zero) but retrieving a type "string".

    Here is the standatrd Skip loop:

    int Data

    for Data in skpAttrs do

    {  attribName = (string key skpAttrs)

       use attribName

    }

     

    Also, I don't think it wise to delete from the Skip while in the Skip.  You could just replace it with "put(skiAttrs, attribName, numAttr, true)".

    -Louie

  • Christopher Cote
    Christopher Cote
    67 Posts

    Re: Trouble getting attribute value from object

    ‏2019-05-24T19:26:42Z  

    First of all, I apologize for the extra post with the same question.  Somehow I didn't think my browser was working and I hit Save again.  I figured out how to get the attribute name from the skip list, but now I want to find out if the current object's attribute is blank.  I now have the following code:

    for obj in currMod do {    for o in skAttrs do {
            attribName = (string key skAttrs);
            if (obj.attribName != "") {
                //Get the number saved in skAttrs for this attribute to increment it.
            }
        }
    }
    

    However, I get an error on the if-statement, which I'm pretty sure is because the code is trying to find an attribute called attribName instead of the value in attribName.  Sorry if I didn't make that clear originally.

     

    Chris

  • Mike.Scharnow
    Mike.Scharnow
    586 Posts

    Re: Trouble getting attribute value from object

    ‏2019-05-25T09:43:04Z  

    First of all, I apologize for the extra post with the same question.  Somehow I didn't think my browser was working and I hit Save again.  I figured out how to get the attribute name from the skip list, but now I want to find out if the current object's attribute is blank.  I now have the following code:

    <pre class="javascript dw" dir="ltr">for obj in currMod do { for o in skAttrs do { attribName = (string key skAttrs); if (obj.attribName != "") { //Get the number saved in skAttrs for this attribute to increment it. } } } </pre>

    However, I get an error on the if-statement, which I'm pretty sure is because the code is trying to find an attribute called attribName instead of the value in attribName.  Sorry if I didn't make that clear originally.

     

    Chris

    try

    if (obj.attribName"" != "")
    

    i.e. don't "compare an AttrRef_ against a string" but "convert an attribute to a string, i.e. extract the value of a string attribute and compare the value against another string"

  • Christopher Cote
    Christopher Cote
    67 Posts

    Re: Trouble getting attribute value from object

    ‏2019-05-28T13:15:54Z  

    Arrggh, those double double-quotes got me again.  I seem to always forget that there's a difference between having them and not.  I'm more used to not needing them from my web development coding days.  Thank you Mike.

     

    Chris