Using Variables in Field.Equation

6 posts / 0 new
Last post
Equipmentman1662
Offline
Joined: 05/23/2018 - 16:46
Using Variables in Field.Equation

Good afternoon Brian,
Love the website, thanks for your dedication to it. I am trying to utilize a variable that I created from the Field Statistics to  count the number of records. However when I put the variable in the Field.Equation line, I recieve a "0" instead of the number of records. The first attachment is the script piece, the second attachment is the results in the databas, where there are "0"s I was expecting the Recordnumber count from the variable RecordCounterResult.
 
Additional Info:
Test_1_Rank is a Character Field, thus the use of the @Val function.
 
Thanks for any insight.

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Hi Equipmentman1662,

I am glad you are enjoying the site.

A couple of things you need to change to make this work.  First the InputBox returns a string and not an interger so change the RecordCounterResult to a string such as:

Dim RecordCounterResult as String

Next you need to modify your equation to:

"@val(@if(TEST_1_RANK="""", """ & RecordCounterResult & """, TEST_1_RANK))"

you need the ampersand (&) in order to concatenate a variable to a string.  You also have to make sure there are three double quotes (") before and after the ampersand as you also need to place the RecordCounterResult between double quotes within the equation or you will get an error that your equation is incorrect.

 

Equipmentman1662
Offline
Joined: 05/23/2018 - 16:46

Thanks Brian. This worked perfectly. 
 

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Glad I could help.

oyarzabalyago
Offline
Joined: 12/27/2019 - 11:41

HI

as I do for the value of the calculated result in the field, pass it to a variable to use it

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57
Hi oyarzabalyago,

You have to use a string variable to equal your equation. I am not sure if the highlighted part is your variable but I will assume it is so that code should look like this:

porcentage_activos = "@ABS((1 * " & num_activos & ")/100)"
field.Equation = porcentage_activos

Hopefully that will fix your problem.