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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Wed May 04, 2016 2:31 am
Alright so using divide works, but then I cant use the whole number and a reminder...
Code: Select all
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.
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Wed May 04, 2016 3:35 pm
Hmmm.
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.
What is the length of tAge?
Craig
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Wed May 04, 2016 8:03 pm
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.
What do you mean by length?
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Wed May 04, 2016 9:36 pm
What do you mean by length?
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:
Code: Select all
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...
Craig
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Wed May 04, 2016 11:17 pm
Alright well I am trying to message you my code directly now. I hope it is an easy fix.
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Thu May 05, 2016 2:22 pm
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?
Code: Select all
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
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Thu May 05, 2016 3:41 pm
When I run this I get this in the variable "tAge":
mlerr, can't find element
Obviously not a number, so the "div" issue seems to be resolved. But I am not familiar with xml stuff.
Craig
-
paul_gr
- Posts: 319
- Joined: Fri Dec 08, 2006 7:38 pm
- Location: Blenheim, New Zealand
Post
by paul_gr » Thu May 05, 2016 8:12 pm
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.
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Thu May 05, 2016 8:23 pm
So you see what Paul has submitted.
How did you get the "add" snippet to work? All the recent hubbub was predicated on the fact that we had a number in tAge.
Craig
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Thu May 05, 2016 10:17 pm
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?
-
dunbarx
- VIP Livecode Opensource Backer
- Posts: 9751
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Post
by dunbarx » Thu May 05, 2016 10:50 pm
Hi.
Still not quite understanding.
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...
Craig
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Thu May 05, 2016 11:10 pm
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.
-
paul_gr
- Posts: 319
- Joined: Fri Dec 08, 2006 7:38 pm
- Location: Blenheim, New Zealand
Post
by paul_gr » Thu May 05, 2016 11:34 pm
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.
Paul
-
CElwell
- Posts: 38
- Joined: Thu Feb 04, 2016 6:29 pm
Post
by CElwell » Thu May 05, 2016 11:45 pm
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.
-
paul_gr
- Posts: 319
- Joined: Fri Dec 08, 2006 7:38 pm
- Location: Blenheim, New Zealand
Post
by paul_gr » Fri May 06, 2016 12:41 am
Up until the last node it looks ok.
I don't think it likes the last node in the XML file
<XmlNode xsi:nil="true"/>
Paul