Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Age") into tAge
divide tAge by 12
put tAge into temp
put "Age: " & temp & return after tData
This gives values such as 5.916667 for 71 divided by 12.
You added the line I suggested, and it worked. And then with that VERY SAME variable, div does not work.
Hmmm.
I could suggest that you write a routine, not hard to do, that translates a decimal like ".9166667" into 11/12, and get your "11" that way. But that is not solving the problem, which is that "div" is throwing an error when applied to a number. Something is terribly wrong, likely very small, and not yet resolved.
Yes. I tried using numberFormat to go between whole number and decimal but you can't do one and then the other later and it will not allow you to have just the decimal value. Do you know another way? I have not seen anything about capabilities of fractions or just decimals.
I am trying to make sure that what appears to be a number is indeed a number. The length of "123" is 3. There could not be any hidden invisible chars in that string.
NumberFormat is a viewing aid. It does not do anything to the underlying argument:
on mouseup
get "123.456789"
set the numberformat to "##.##"
put it + 0 into fld 1
answer it
end mouseup
I am not willing to go down the path of creating a 1-of-12 decimal-to-digit extractor. It is simple to do, but silly, since div and mod should work for this purpose.It is what they do.
You may have to post your stack. There is a gremlin somewhere...
Alright so this is my code and we believe there is possibly a problem as the last value given is an error as when the xml code ends it hits this error and stops. Does anyone know how to fix that?
on preOpenStack
put url "http://www.petango.com/webservices/wsadoption.asmx/AdoptableSearch?authkey=7dv5i25uco18t21260a35h2gqnihe60d3gy7saige7ahc26r7d&speciesID=&sex=&ageGroup=&location=&site=&onHold=&orderBy=&primaryBreed=&secondaryBreed=&specialNeeds=&noDogs=&noCats=&noKids=&stageID=" into tURL
put revCreateXMLTree( tURL, true, true, false) into tInfo
put revXMLChildNames( tInfo, "ArrayOfXmlNode", return, "XmlNode", true) into tChildren
repeat for each line tChild in tChildren
add 1 to x
put revXMLChildNames( tInfo, "ArrayOfXmlNode/"&tChild&backslash, return, "adoptableSearch", true) into tAdoptable
put "ID: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/adoptableSearch[1]/ID") & return after tData
put "Species: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Species") & return after tData
put "Sex: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Sex") & return after tData
put "Breed: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/PrimaryBreed") & " / " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/SecondaryBreed") & return after tData
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Age") into tAge
put tAge div 12 into tYears
put tAge mod 12 into tMonths
put "Age: " & tYears & " years" & " " & tMonths & " months" & return after tData
put return after tData
end repeat
put tData & return after tOutput
set the text of field "tData" to tOutput
end preOpenStack
Two error messages.
first error message is "bad document ID", then the second is "xmlerr, can't find element"
The initial load of the XML file is correct.
tAge is not a number.
Paul
Last edited by paul_gr on Thu May 05, 2016 10:40 pm, edited 3 times in total.
I was using "add 1 to x" as I believed you needed it as you moved to the next node, but I am a beginner so that may be unnecessary. When I comment it out it does not change any of the result.
"tAge" has to be a number or I wouldn't being getting a number age in months outputted into my result. What is wrong with how my xml is being put into the result?
Are you saying that you (seem to) get a number in tAge? That is one issue.
And that the "add" line works, but the "div" line does not? That is another.
To anyone else: Is one person's call to these xml gadgets possibly different from another's, susceptible to changes of any kind, depending on the phases of the moon, or whatever? That is a third...
One. I get an age output as a number in months for each node except the last one when all of the information comes out with an error.
Two. I do not believe the "add" was doing anything actually. However, I can use the "divide" and get a correct value, but I can't use "div."
I think it has to do ith this error when it tries to get data past the last node because I used "isNumber" and I get true until it reaches the end where there is an error.
CElwell wrote:One. I get an age output as a number in months for each node except the last one when all of the information comes out with an error.
Two. I do not believe the "add" was doing anything actually. However, I can use the "divide" and get a correct value, but I can't use "div."
I think it has to do ith this error when it tries to get data past the last node because I used "isNumber" and I get true until it reaches the end where there is an error.
Good, I agree with you so far.
You are getting closer to solving this.
Problem is that I don't know why it is going past the last node and getting an error as the repeat tells it to do so for the lines in the xml and nothing further. My knowledge for Livecode is very limited so I am not really sure what the problem could be with this.