Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 10th, 2025, 3:04 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Calculation and display of averages.
PostPosted: November 22nd, 2006, 2:47 pm 
Offline

Joined: December 6th, 2005, 6:18 pm
Posts: 23
Hi

I'm trying to calculate and display the average of 5 variables. Each var is the time taken for a user to tap on a graphic (a reflex speed timer) the clock starts when the graphic appears and stops when it's tapped. This happens 5 times producing five results. I want to sum the results and produce an average, to be displayed in a text box.

The problem is finding out how to script the calculation and assign the function to a button. I wont go through the ways I've tried but rest assured I've tried a few. Hell, I've even tried reading the manual.

Any ideas?

Pretty please?

Peter

_________________
Peter Loader

Educational Content Development
-----------------------------

ploader@learningtrust.co.uk
http://www.learningtrust.co.uk

Opus XE 5.14, Windows XP SP2, 3.6Ghz P4, 3Gb RAM


Top
 Profile  
 
 Post subject: Calculation = Expression
PostPosted: November 22nd, 2006, 3:24 pm 
Offline

Joined: October 25th, 2004, 2:20 pm
Posts: 686
Location: Naperville, Illinois (USA)
Opus: 7.05
OS: Win XP SP3
System: P4 3.2GHz 1GB RAM 2-TB HDs + 4 more
Peter --

IF you have already created the five Variables you need, this should be very simple.

Create a Text Object (or in your case a Button Object). If you want to type verbage to describe what comes next, go ahead (example "Here is the average of all five scores "). Don't forget to leave a space after the last character, otherwise things will run together.

While still inside the Text Object (Button), do a right mouse click. In the middle of the window which opens, left click "Insert Variable or Expression." The default is to insert a Variable. You want a Constant Expression, so click that option. Remember how to find an AVERAGE? Add each item together, then divide by the number of items. You want to group the "adding" function THEN do the division, so here's how it would look:

(Var_1 + Var_2 + Var_3 + Var_4 + Var_5) / 5

The "(" and ")" group that calculation together. The "/" means to divide, and the "5" is the number of variables you have. Sorry if you already know all this. You MUST have your variables already created BEFORE you get to this step. When you are finished, the words "Expression OK" should be at the bottom of the window. If not, you've got something incorrect.

Click OK, and run in Preview to check your answer. You obviously want your Variables populated with numbers to verify everything.

_________________
Fred Harms, Extraordinary Demos
Naperville, Illinois (USA) 630/904-3636
demofred@aol.com


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 22nd, 2006, 3:27 pm 
Offline

Joined: November 3rd, 2004, 2:11 pm
Posts: 323
This is what I did:

Code:
FINVAR=var1+var2+var3+var4+var5;
FINVAR=FINVAR/5;
FINAVG=FINVAR;


Where var1-var5 contain your times. Depending upon how you've set up your variables you may need to convert them to a number by eval(varx), and then do the average math.

Hope this helps.

_________________
Opus Pro XE 9.1 Win7 64-bit Core i3 8MB RAM


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 22nd, 2006, 3:27 pm 
Offline

Joined: November 3rd, 2004, 2:11 pm
Posts: 323
Darn Fred! You beat me to it.

_________________
Opus Pro XE 9.1 Win7 64-bit Core i3 8MB RAM


Top
 Profile Visit website  
 
 Post subject: High Speed Modem WINS
PostPosted: November 22nd, 2006, 3:36 pm 
Offline

Joined: October 25th, 2004, 2:20 pm
Posts: 686
Location: Naperville, Illinois (USA)
Opus: 7.05
OS: Win XP SP3
System: P4 3.2GHz 1GB RAM 2-TB HDs + 4 more
Brian --

It must be my "high speed cable modem" (LOL)!

In your solution, you have to create additional Variables to collect the sum. Being "lazy", I prefer to just use math symbols, then let OPUS do the number crunching. I'd use your method IF I needed the sum of the five Variables multiple times elsewhere in the Pub.

Which ever solution makes the most sense to Peter will be the one he uses. Now back to taking a "nap". All this math makes my brain tired.

_________________
Fred Harms, Extraordinary Demos
Naperville, Illinois (USA) 630/904-3636
demofred@aol.com


Top
 Profile Visit website  
 
 Post subject: Thanks so far
PostPosted: November 29th, 2006, 4:20 pm 
Offline

Joined: December 6th, 2005, 6:18 pm
Posts: 23
I went with Freds as my first choice but ended up wtih a problem. Rather than sum the variables it appended them to create a string of numbers.

as an example. 4 variables, populating themselves sequentially.

var1 input 4 average was 1 so far so good.
var2 input 4 average was 11 here it goes oops!
var3 input 4 average was 111
var4 input 4 average was 1111

thats using (var1 + var2 + var3 + var4)/4 as the display variable.

It seems pretty simple mathematically and the averages are being calculated correctly but the display goes tits-up. The clocks are set to count [ss]

Actually I need millisecs but one step at a time!

Any ideas?

Cheers guys and girls.

_________________
Peter Loader

Educational Content Development
-----------------------------

ploader@learningtrust.co.uk
http://www.learningtrust.co.uk

Opus XE 5.14, Windows XP SP2, 3.6Ghz P4, 3Gb RAM


Top
 Profile  
 
 Post subject:
PostPosted: November 29th, 2006, 7:22 pm 
Offline

Joined: November 3rd, 2004, 8:12 pm
Posts: 129
Location: New Brunswick, Canada
Opus: 8.6
OS: Win 8 (ASUS) - Win 7: (ASUS)
System: Asus - Windows 7 - 8 - Intel Core 3 - 4RAM - 16RAM
Peter,

have a look at the attached zip file.


You do not have the required permissions to view the files attached to this post.

_________________
Leo Taylor
Win XP Home / Opus Pro 7.01 & 6.4 / P4-2.8 / 1.5 GB RAM / ATI All-in-Wonder 9600 /160GB-HD


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 29th, 2006, 9:10 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
rather than::

(var1 + var2 + var3 + var4)/4

you can force a numerical output with::

(Number(var1)+Number(var2)+Number(var3)+Number(var4))/4

Otherwise the '+' operator can treats the variables as strings and
concatenates them.

You often don't need to use "Number(variable)", but if Opus thinks any part of an addition calculation is a string, you will get a string as output, and 1 + 1 + 1 will be given as 111.

Paul


Top
 Profile  
 
 Post subject: Numbers not Text
PostPosted: November 29th, 2006, 11:46 pm 
Offline

Joined: October 25th, 2004, 2:20 pm
Posts: 686
Location: Naperville, Illinois (USA)
Opus: 7.05
OS: Win XP SP3
System: P4 3.2GHz 1GB RAM 2-TB HDs + 4 more
Peter --

My first quess as to why you are having a problem goes to when you created your Variables. You can choose to have a Variable be a number or text. Text can have numbers in them, but you can't ADD "Fred" and "Peter". It would come out "FredPeter" at best.

Go back and re-create your Variables and make sure you tick where it shows Numbers.

_________________
Fred Harms, Extraordinary Demos
Naperville, Illinois (USA) 630/904-3636
demofred@aol.com


Top
 Profile Visit website  
 
 Post subject: Thanks to everyone
PostPosted: November 30th, 2006, 4:33 pm 
Offline

Joined: December 6th, 2005, 6:18 pm
Posts: 23
A note to say a big THANK YOU to everyone who lent me a hand with this. It's working just fine now.

I'm amazed at the amount of people who are willing to help out and spend their time contributing to other peoples problems, if you see what I mean!

Quite a community.

_________________
Peter Loader

Educational Content Development
-----------------------------

ploader@learningtrust.co.uk
http://www.learningtrust.co.uk

Opus XE 5.14, Windows XP SP2, 3.6Ghz P4, 3Gb RAM


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 31 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