LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Glenn Boyce
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
Post
by Glenn Boyce » Wed Jan 13, 2010 3:05 am
I have attached some code below. I am having trouble formatting the data in the fields, having had a number of attempts. What is the correct cods and where does it go?
Code: Select all
repeat with n = 1 to 12
if fld ("UOM"&n) = "gm" then
put fld ("QTY"&n)/1000 into tQTY
else
put fld ("QTY"&n) into tQTY
end if
put fld ("cost"&n) * tQTY into tsubtotal
put tsubtotal into fld ("subtotal"&n)
add tQTY to tTotalQty
add fld ("subtotal"&n) to tTotalCost
fld ("subtotal"&n) is a dollar figure. When I put the format #.00 command in the line before it formats the "n" and screws the script!!
thanks
-
Klaus
- Posts: 14198
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Wed Jan 13, 2010 10:17 am
Hi Glen,
1. do you mean "set the numberformat to x.xx" or the "format" function?
2. Where do you put this?
3. What and how gets screwed?
A little more info would help me to help you
Best
Klaus
-
Glenn Boyce
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
Post
by Glenn Boyce » Thu Jan 14, 2010 4:15 am
I've included the actual code below:
Code: Select all
repeat with n = 1 to 12
if fld ("UOM"&n) = "gm" then
put fld ("QTY"&n)/1000 into tQTY
else
put fld ("QTY"&n) into tQTY
end if
put fld ("cost"&n) * tQTY into tsubtotal
--set the numberformat to "#.00"
put tsubtotal into fld ("subtotal"&n)
add tQTY to tTotalQty
add fld ("subtotal"&n) to tTotalCost
end repeat
I used the "set the number format and what happens is that it sets the number format of "n" to #.00 and the script wil not run.
cheers
Glenn
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sun Jan 17, 2010 1:35 pm
Dear Glenn,
What does "the script does not run" mean? Do you get an error message? If you get an error message, you should always post it together with your question on this forum.
Does the following script work for you? If not, where does it go wrong? Do you still get an error message?
Code: Select all
repeat with n = 1 to 12
if fld ("UOM"&n) = "gm" then
put fld ("QTY"&n)/1000 into tQTY
else
put fld ("QTY"&n) into tQTY
end if
put fld ("cost"&n) * tQTY into tsubtotal
set the numberformat to "#.00"
put tsubtotal*1 into tsubtotal
set the numberformat to "#"
put tsubtotal into fld ("subtotal"&n)
add tQTY to tTotalQty
add fld ("subtotal"&n) to tTotalCost
end repeat
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
Glenn Boyce
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
Post
by Glenn Boyce » Mon Jan 18, 2010 3:37 am
Hi Mark
Don't get an error message but the number in fld ("subtotal"&n) is just an integer
cheers
Glenn
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10327
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Fri Jan 22, 2010 4:02 pm
I have played with this,too. Setting the numberFormat pretty much locks in the way numbers are treated in Rev. So if you say:
set numberformat to "#.00"
put 1 into y
add 0 to y
answer y
You get "1.00".
This makes your field references wrong, since you wanted field "myField1" but Rev thought it was field "myField1.00"
You can fix this by extracting only the integer portion. In your script, for example:
put tsubtotal into fld ("subtotal"& char 1 to offset(".",n) - 1 of n)
will get rid of that pesky decimal portion of the number
Craig Newman