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:


[TABLE="class: brtb_item_table"][TBODY][TR][TD]Product 1[/TD][TD]100[/TD][TD]104[/TD][TD]97[/TD][/TR]
[TR][TD]Product 2[/TD][TD]247[/TD][TD]238[/TD][/TR]
[TR][TD]Product 3[/TD][TD]1207[/TD][TD]1187[/TD][TD]1193[/TD][TD]1282[/TD][/TR][/TBODY][/TABLE]
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!
 
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
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!
 
  • Спасибо
Реакции: bartjan

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