calculating

You have completed your first interactive designs with QuarkXPress 7, 8 & 9 and now have need for more advanced functionality. Discuss Expressions here, ask questions and learn more about them.
Please note that Flash (SWF) authoring is not supported in QuarkXPress 10 anymore.
Frans van Huizen
Posts: 0
Joined: 12 Jul 2009, 09:16

calculating

Post by Frans van Huizen » 14 May 2010, 03:04

Hello Mathias,I'm building a flashsite with interactive right now for our company.In one item i want to calculate e.g. in a textfield you can put a number and the result in an other field has to be the input times 20.Can you give me an example for the expression.With kind regardsFrans van Huizen

Jyoti Bhatnagar (Quark)
Posts: 93
Joined: 31 Dec 1969, 19:00

calculating

Post by Jyoti Bhatnagar (Quark) » 16 May 2010, 17:16

Hello Frans van Huizen,
Please check out short tutorial on expression at t/22934.aspx.
Here examples are also shared.
Thanks,
JB

Matthias Guenther (Quark)
Quarkian
Quarkian
Posts: 2490
Joined: 04 Jun 2004, 15:06
Contact:

calculating

Post by Matthias Guenther (Quark) » 16 May 2010, 21:01

Hi Frans,
under the link Jyoti posted you'll find the rigth instructions.
Basically you use Textboxname1.GetNum() to get the value out of the textbox and store that in a variable (not necessary but more flexible), multiply the variable by using var=var*20 and then put that into another text box usingTextboxname2.Append(variable).
Thanks
Matthias

Frans van Huizen
Posts: 0
Joined: 12 Jul 2009, 09:16

calculating

Post by Frans van Huizen » 17 May 2010, 02:40

Hi Matthias,I made the script as you described, but i get in the resultfield the code NaN, is that an error code.My script is build as follow:Set "calcbon = INV_bonwaarde.GetNum()"Set " calcbon = calcbon*20"Set " Totaalbedrag.Append(calcbon)"Calcbon = the variable wit an integerINV_bonwaarde = a textbox wich is editable, datatype anyTotaalbedrag = a textbox simpleIf i put a number in the field INV_bonwaarde, it gives the result NaN in the field Totaalbedrag.Is NaN an error code, and what is wrong with my script.regards Frans

Matthias Guenther (Quark)
Quarkian
Quarkian
Posts: 2490
Joined: 04 Jun 2004, 15:06
Contact:

calculating

Post by Matthias Guenther (Quark) » 17 May 2010, 03:01

Hi Frans,
looks right. When and how do you trigger your script?
NaN stands for "Not a Number", so it looks like the input text box is empty when you assign itscontent to the variable.
Regards
Matthias

Frans van Huizen
Posts: 0
Joined: 12 Jul 2009, 09:16

calculating

Post by Frans van Huizen » 17 May 2010, 04:00

I found out what the problem is.
In the vlaue i use a comma as separor so 0,80
If i use a dot it caculates right, but i like to use a comma.
And the result is now 0.80 * 20 = 16 instead of 16.00, so i think i have to trim the value, but how

Matthias Guenther (Quark)
Quarkian
Quarkian
Posts: 2490
Joined: 04 Jun 2004, 15:06
Contact:

calculating

Post by Matthias Guenther (Quark) » 17 May 2010, 04:45

Hi Frans,
well, functions in programming languages (like the internal ActionScript SWF uses and that you don't see) often expect the numbers in English formats, so a dot as the decimal delimiter and not a comma.
If you need a comma, then you need to convert the number entered into an English format, calculcate and then format back. That's not an easy expression.
Also, it wouldn't catch any errors if your customers type in two commas or letters. Maybe another user interface (buttons or arrows) to select values is better?
Tell me what you want me to do please.
Thanks
Matthias

Frans van Huizen
Posts: 0
Joined: 12 Jul 2009, 09:16

calculating

Post by Frans van Huizen » 17 May 2010, 04:52

Hi Matthias,Well i go for the hardway :-)) it always must be a comma and the result must always has two digits after the comma.So please help me with the difficult expression.Regards Frans

Matthias Guenther (Quark)
Quarkian
Quarkian
Posts: 2490
Joined: 04 Jun 2004, 15:06
Contact:

calculating

Post by Matthias Guenther (Quark) » 17 May 2010, 23:01

Hi, Frans,
ok, I'll give you the input part, maybe you can think of the output part yourself.
Beware, the Expressions get long ;-)
To Do:
1. Create a variable "calc", type decimal.
2. Create a variable "calcstring", type string.
3. Create a textbox object, editable, called "inbox" (here your user enters his/her number).
4. Create a textbox object called "outbox" (here the result will be shown).
5. Create a script
Reset Object > outbox
Set Expression: calcstring=inbox.GetText()
If Expression: calcstring.IndexOf(",",0) Set Expression: calc=calcstring.Left(calcstring.IndexOf(",",0)).StrToNum() +calcstring.SubStr(calcstring.IndexOf(",",0)+1,1).StrToNum()/10
Else
Set Expression: calc=calcstring.Left(calcstring.IndexOf(",",0)).StrToNum() +calcstring.SubStr(calcstring.IndexOf(",",0)+1,1).StrToNum()/10 +calcstring.SubStr(calcstring.IndexOf(",",0)+2,1).StrToNum()/100
End If
End If
Set Expression: calc=calc*20
outbox.Append(calc)
6. Now create an object (button) that triggers the script.
Does that work?
Explanation:
The blue lines are the expressions you are looking for (they are on oneline, I just split them to make it easier to read). I need two, as I do not know whether the user enters one or two decimals. They basically search for the position of the first comma and then split the first part of and add the numbers after the comma as fractions. Makes sense? The rest of the script is just for figuring out, which expression should be used ;-)
Alternative:
After I finished this I came up with an easier alternative, by searching for a comma and replacing it with a period. However then your form woudl show a period, so you might want to first copy the string to another (invisible) box, if you want to go this alternative route.


And as said, the only thing that still needs to be done is the part that the output needs to exchange the period for a comma, for that the search and replace alternative is great!

Thanks
Matthias

Frans van Huizen
Posts: 0
Joined: 12 Jul 2009, 09:16

calculating

Post by Frans van Huizen » 18 May 2010, 02:32

Hi Matthias,Thank you for your reply and all the work.The script works but.... in the outputbox i dont get a four digit number, but only e.g. 0,80 x 20 = 16Do you have an explanation for this?In meen time i will try to figure out the replacement for the period by an comma.Greets Frans

Locked

Return to “Expressions”