Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently May 18th, 2024, 7:06 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Adding Numbers to variable
PostPosted: March 29th, 2016, 11:46 am 
Offline

Joined: May 12th, 2015, 2:04 pm
Posts: 47
Opus: Opus 9.5
OS: Win 8
System: Intel Core i7 3.6Ghz
Good Day,

I am publishing a html5 website, on one of the pages the user adds products to his/her cart and a <GrandTotal> variable is displayed...the problem is as follows:

When a user let say buys products value of:

Product 1 -- 400
Product 2 -- 120
Product 3 -- 140

The <GrandTotal> value displays this : 400120140 when I refresh the page and do it again the correct value of 660 is displayed. Always on the first attempt the add variable do not add up but it looks like it treats it as a string and add to existing content???

Is this a bug?


For this message Matra has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: March 29th, 2016, 2:13 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Make sure all your variables are numbers before performing arithmetic. Something like:

Code:
Number(VAR_A) + Number(VAR_B) + Number(VAR_C)

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: March 30th, 2016, 7:20 am 
Offline

Joined: May 12th, 2015, 2:04 pm
Posts: 47
Opus: Opus 9.5
OS: Win 8
System: Intel Core i7 3.6Ghz
Hi Mackavi,

Hope you are good.

So I must make use of scripting and not opus actions?


For this message Matra has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: March 30th, 2016, 11:08 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Yes, although this is a basic section question, I would suggest that you perform arithmetic in a script rather than actions when publishing to HTML5.

If you're interested the reason the problem occurs is that JavaScript (used in HTML5) is a loosely typed language which means that a variable can change between a string and a number depending on how it is used. As JavaScript uses the plus (+) operator to both perform addition arithmetic and concatenate strings, your intention can be misinterpreted.

Although not a bug, I think it might be worth asking DW to change the way the actions work because at this level, I think it's fair to assume the ADD Action would perform the arithmetic operation. And maybe some extra actions for specifically joining or manipulate strings could also be included like they use in the Scratch editor.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: July 24th, 2017, 6:11 pm 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
So Mack,

How do I use Opus script to add 1 to a variable as the Opus action is appending it?

I have a variable <value 1> which is a number and I want to add "1" to it. The Opus action is sometimes appending it and making it "11" so I am guessing a script would be better. I can't get the syntax correct.

Bob

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: July 24th, 2017, 11:18 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
For scripting, you just use the Number function above to solve the problem.

</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Adding Numbers to variable
PostPosted: July 25th, 2017, 10:58 am 
Offline

Joined: June 26th, 2007, 11:59 am
Posts: 60
Opus: Opus 9.01
OS: Windows 7
System: Heinz 57
My variable that is being added to is <environs>.

I have added the following code to the Opus Script action but it still appends the number to 11 and fails in the publication as a result.
All text boxes that show the variable for testing purposes have been removed. The following works in a test publication but not when I amend the main pub.

Is my syntax wrong Mack?

Number.environs //converts variable to number
environs = environs + 1

Help appreciated

Bob

_________________
Opus Pro v7, Windows XP Pro SP2, Intel Core 2 , Quad CPU Q6600 @ 2.4GHz, 1GB RAM, Partitioned HD 10 GB & 30 GB. Internet Explorer 7.


For this message DaveB56 has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group