This article applies to:

E-Prime 3.0

E-Prime 2.0

E-Prime 1.x

Detail

String variables can be used to perform **some **math operations in E-Basic. For example:

Dim strValue1 As String, strValue2 As String

strValue1 = 20

strValue2 = 10

strValue1 = strValue1/strValue2

Debug.Print strValue1

This code results in a value of "2" being printed to the Output window in E-Studio. It is important to note that the addition (i.e., +) operator **DOES ****NOT **work in this manner. That is, instead of performing a mathematical operation, the addition operator concatenates the two strings. So, in the previous example, instead of printing "30" to the Output window, it would print "2010". However, all other basic operations (i.e., subtraction and multiplication) perform the corresponding math operation.

It is also possible to use String variables to perform math operations with real numbers. For example, using 20.22 and 10.10 for the strValue1 and strValue2 variables, respectively, results in "2.0019801980198" being printed to the Output window.

One caveat to this feature is that if a String variable holding a real number is used in a numerical greater-than (>) or less-than (<).

Dim strValue As String

strValue = 3.14

Dim nValue As Double

nValue = 3.14

If strValue > 3 Then

Debug.Print "String-to-Integer comparison successful."

End If

If nValue > 3 Then

Debug.Print "Double-to-Integer comparison successful."

End If

In the above code, only the second comparison evaluates to true. This is because the first comparison uses only the value that precedes the decimal point when performing the comparison. However, the strValue variable still holds 3.14 once the comparison is finished. When using String variables to perform math operations and/or comparisons, it is important to ensure that this aspect does not adversely affect your experiment.

For more information view the E-Prime Command Reference for specifics involving E-Basic (https://pstnet.com/ecr).

## Comments

0 comments

Please sign in to leave a comment.