Calculate string expression

Calculate string expression

rikard.nilsson4SLAL
Participant Participant
229 Views
2 Replies
Message 1 of 3

Calculate string expression

rikard.nilsson4SLAL
Participant
Participant

Hi,

I'm trying to calculate an expression in a string to create a double in iLogic.

 

I've done som e searching and I think is DataTable is the best way of solving that. I try with the the row below.

 

result = New DataTable().Compute("1 + 2 * 7", Nothing))

 But I get that DataTable is not defined.. 

I tried with different imports like..

Imports System.Data

 

But nothing works.

Does anybody know what I should import to get this working in iLogic or do anybody have another solution how to calculate string expressions?

 

Regards

Rikard

0 Likes
Accepted solutions (1)
230 Views
2 Replies
Replies (2)
Message 2 of 3

FINET_Laurent
Advisor
Advisor
Accepted solution

Hello @rikard.nilsson4SLAL,

 

You need to add the references first before importing the class :

AddReference "System.Data.dll"
AddReference "System.Xml.dll"

Imports System.Data
Imports System.Xml

Sub Main()
    Dim expression As String = "1 + 2 * 7"
    Dim result As Object = New DataTable().Compute(expression, Nothing)
	
	MsgBox(result)
End Sub

 

FINET_Laurent_0-1709627064621.png

 

Kind regards,

FINET L. 

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 3

rikard.nilsson4SLAL
Participant
Participant
Yes of course!!
Thank you so much!

/Rikard
0 Likes