Skip to main content

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.

Brian Element Mon, 05/20/2019 - 14:04

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.

 

oyarzabalyago Tue, 11/10/2020 - 08:37

HI

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

Brian Element Tue, 11/10/2020 - 11:16

In reply to by oyarzabalyago

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.
The website encountered an unexpected error. Try again later.