Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将逻辑表达式保存到以后可以计算的文件中_Vb.net - Fatal编程技术网

Vb.net 将逻辑表达式保存到以后可以计算的文件中

Vb.net 将逻辑表达式保存到以后可以计算的文件中,vb.net,Vb.net,我正在创建一个应用程序,允许用户使用位逻辑表达式。同一个应用程序稍后也会计算这些逻辑表达式,引用内存中的变量。处理这种性质问题的一般方法是什么 Variables in memory (example) Variable Type Value height string tall plans integer 3 Examples of logical expressions a user may have entered: height = "tall

我正在创建一个应用程序,允许用户使用位逻辑表达式。同一个应用程序稍后也会计算这些逻辑表达式,引用内存中的变量。处理这种性质问题的一般方法是什么

Variables in memory (example)
Variable   Type      Value
height     string    tall
plans      integer   3

Examples of logical expressions a user may have entered:
height = "tall"
plans > 3
Left(height, 1) = "s"
height = "tall" AND plans > 3
我考虑过使用正则表达式、反射或编写编译器或解析器。
由于所有这些选项对我这样有经验的人来说都是“困难的”,我想知道哪种方法对我的问题最有意义,或者是否有更合适的方法?

将表达式存储在Excel语法中并使用Excel。评估

使用布尔值标记哪些变量值是数值,并且应在逻辑字符串中省略引号

使用元字符表示变量(即“@”字符),并在计算之前用它们的值替换它们。 这种方法易于实现,用户可以访问Excel的公式

 Imports Microsoft.Office.Interop

 Dim xlApp As Excel.Application
 Dim variables As DataTable
 Dim initialString As String 'this is the logic string
    For Each row As DataRow In variables.Rows
        If DirectCast(row.Item("Numeric"), Boolean) Then
            initialString = Strings.Replace(initialString, _
                "@" & DirectCast(row.Item("Variable"), String), _
                DirectCast(row.Item("VarValue"), String))
        Else
            initialString = Strings.Replace(initialString, _
                "@" & DirectCast(row.Item("Variable"), String), _
                """" & DirectCast(row.Item("VarValue"), String) & """")
        End If
    Next
    MsgBox(xlApp.Evaluate(initialString))

plans=“tall”
这样的表达式会发生什么情况?最好是计算为真/假以外的第三个值,或者抛出错误。我可以在用户创建expressions.IIRC时检查类型一致性,这要求用户安装了Excel/Office。确保列出所有依赖项。