# Adding numeric variables in Lectora

Community Member Posts: 39
I must be missing something simple. I have two variables I want to add to generate the contents of a 3rd variable..... so I have V1, V2, and V3. I want V3=V1+V2   I can see how to add constants, I don't see how to add numeric variables. I assume all variables are string, do I have to convert them some way to numeric?

• Community Member Posts: 34 ♪ Opening Act ♪
Using the examples you have...

Under modify variable, set target as V3

type: set equal to

value: VAR(v1) + VAR(v2)

So when V3 is modified, it will take the value of V1 and V2 added together.

In the Value field, click on the little grey box with an arrow in the right lower corner. This will open a window that will let you put the formula you want together quickly.

Hope that helps!
• Community Member Posts: 39
That is getting me very close thank you......but if v1=2 and v2=5 instead of giving me 7 it displays 2+5 ...so somehow I need to convert that from string to numeric.
• Community Member Posts: 1,205 ♦ Idol ♦
You can try the classical way:

Action: Modify variable

Target: v3

Type: Set equal to

Value: VAR(v1)

<hr />

Action: Modify variable

Target: v3

Value: VAR(v2)
• Community Member Posts: 34 ♪ Opening Act ♪
Ha! Sorry--totally spaced on that. Good that Tim knows what's up for reals.

On a positive note, if you ever need to string things together now you know how
• Community Member Posts: 39
Thank you, both of you, Erica and Tim, that did it. I forgot that all math ops are binary and must be done in individual actions. I had hoped I could do a math op in the value box but evidently you cannot.

This is kind of sucky though..my actual formula was nastier, something like A+B*C+D*E, and I didn't want the original results of A, C, and E destroyed.  I then had to create 2 new variables: prodBC and prodDE.

Now I had to create an action to make prodBC=C and another action to make prodDE=E

Then I had to create a new action to make prodBC*B and another to make prodDE*D

I then had to add things two at a time. I created a new variable TOTALscore and then created an action that made that equal to A. I then created a new action to take TOTALscore and add to it prodBC. I then had to make a final action to take TOTALscore and add it to prodDE.

This is just nasty.  I ought to have a single line where I can put  in the var names (surrounded each by VAR and parens and have it then interpret that result.
• Community Member Posts: 988
Why not just use JavaScript?