Basic math question

Saladetomateoignons

Новичок
Регистрация
16.09.2018
Сообщения
6
Благодарностей
0
Баллы
1
Hi,

The more I play around with Zennoposter, the more I think it's awesome.

I'm facing a problem though, which is probably simple to solve for most but not for a newbie like me, especially since I don't have any programming skills. Maybe someone could help me overcome this issue. Thanks in advance.

Goal:

Calculate the average of a sum on the fly.

The data I have

In my source table I have a list of prices I collected for products. I could be one price or up to 4 (which is the maximum number of prices), it changes from line to line. Here is an example:


Product 110010497
Product 2247238
Product 31207118711931282
[TBODY] [/TBODY]
I'd like, for each line, get the average.
For example, for product 1: (100+104+97)/3=100,33

How I see the problem

Parsing is not really an issue. What is a problem for me is doing the math (since I don't know javascript, I'm not 100% of what piece of javascript code to look for and what I've searched around doesn't answer my question).

I understand that I can use javascript in the project for basic math, such as {-Variable.Product1-}+{-Variable.Product2-} or ({-Variable.Product1-}+{-Variable.Product2-})/3

However I can't add more than two variables like {-Variable.Product1-}+{-Variable.Product2-}+{-Variable.Product3-}. It doesn't work.

I could of course try:
  1. {-Variable.Product1-}+{-Variable.Product2-} then assign result to variable (say {-Variable.Result1-})
  2. {-Variable.Product2-}+{-Variable.Result1-}/3
However it seems terribly inefficient to me, especially if you have plenty of prices to add. If feel that there is another way, but I can't tell what.

Just to let you know, here is how I plan to parse the original data

So I have this table you saw above with the products in a .xlsx file.

In Zennoposter, I plan to do the following actions:
  1. assign the file to a table
  2. call a line of the table (order doesn't matter) and delete it after taking it
  3. assign the cells to a variable
  4. create a List and add one variable (price) per row
  5. do row count on the List to get the divider (to divide the sum of prices to get the average) and assign it to a variable (say {-Variable.Divider-}
  6. do the javascript math (my problem)
Any help would be appreciated. Thanks in advance!
 

bartjan

Client
Регистрация
01.02.2011
Сообщения
29
Благодарностей
2
Баллы
3
adding multiple variables in javascript works fine for me
something like this: https://www.dropbox.com/s/fwnm7vsvoqor4ey/Calc AVG.zip?raw=1 (sorry i have no idea how to add files in the forum as it's all Russian)

part of me is wondering why you're not simply using the AVERAGE function in excel though, as that's super simple.
 
  • Спасибо
Реакции: Saladetomateoignons

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 233
Благодарностей
5 846
Баллы
113
If you don't know how to perform math actions, you can do it using own code.
Here examples:
Код:
   int a = int.Parse(project.Variables["var1"].Value);
   int b = int.Parse(project.Variables["var2"].Value);
JavaScript:
{-Variable.var1-}+{-Variable.var2-}
 
  • Спасибо
Реакции: Saladetomateoignons

Saladetomateoignons

Новичок
Регистрация
16.09.2018
Сообщения
6
Благодарностей
0
Баллы
1
Thank you to both of you.

I tried again and now it works add more than 2 variables... I'm not sure of why it couldn't work but now it does. Thank you again!
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
  • Спасибо
Реакции: bartjan

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)