السلام عليكم ورحمة الله
الحمد لله، وجدت لك طريقة من أحد مشاريع الأخوة مختلفة تماما عما سبق، ولا تحتاج أي تعديلات من جهتك
جرب التالي
PHP كود :
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim AbNormal = "N"
Dim SN = 1500
Dim Gender = "Male"
Dim PValue = 11
Dim condition As String = "(AbNormal = 'N' ( [1500] ) And Gender = 'Male') Or (AbNormal = 'N' And PValue >= 11)"
Dim result As Object = f(AbNormal, SN, Gender, PValue, condition)
If result IsNot Nothing Then
If result Then
MsgBox("Valid")
Else
MsgBox("Invalid")
End If
Else
MsgBox("Error")
End If
End Sub
Public Function f(ByVal AbNormal As Char, ByVal SN As Integer, ByVal Gender As String, ByVal PValue As Integer, ByVal condition As String) As Object
Try
Dim code As String = _
"Dim AbNormal As Char=""" & AbNormal & """,Gender As String=""" & Gender & """,SN As Integer=" & SN & ",PValue As Integer=" & PValue & vbCr & _
"If " & condition & " Then Return True Else Return False"
code = "Class c" & vbCr & "Function f() As Boolean" & vbCr & code & vbCr & "End Function" & vbCr & "End Class"
code = Replace(code, "'", """") : code = Replace(code, "( [", " And SN=") : code = Replace(code, "] )", " ")
code = Replace(code, "([", " And SN=") : code = Replace(code, "])", " ")
Dim res As System.CodeDom.Compiler.CompilerResults = New VBCodeProvider().CompileAssemblyFromSource(New CodeDom.Compiler.CompilerParameters, code)
Dim ins As Object = res.CompiledAssembly.CreateInstance("c")
Dim methodInfo As Reflection.MethodInfo = ins.GetType.GetMethod("f")
Return methodInfo.Invoke(ins, Nothing)
Catch ex As Exception
End Try
Return Nothing
End Function
End Class

