تنفيذ معادلة حسابية كاملة
الكاتب الأخ :**أبورائد**
السلام عليكم ورحمة الله وبركاته
كيف تنفذ معادلة حسابية كاملة عن طريق مترجم الفجوال بيسيك
هذا الكود كنت سأضعه أمس ولكن الظرف الموجود في التوقيع كان مفاجأ.
******المعذرة قد أغيب يومين*****
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Calculate(Me.TextBox1.Text))
End SubPublic Function Calculate(ByVal mExpression As String) As Double
Dim mProvider As New VBCodeProvider
Dim mCompilerParameters As New CodeDom.Compiler.CompilerParameters
mCompilerParameters.GenerateExecutable = False
mCompilerParameters.GenerateInMemory = True
Dim mSource As String = _
"Public Class mCompile " & vbNewLine & _
" Public Shared Function mCalculate() " & vbNewLine & _
" Return " & mExpression & " " & vbNewLine & _
" End Function " & vbNewLine & _
"End Class "
Dim mCompilerResults As CodeDom.Compiler.CompilerResults = mProvider.CompileAssemblyFromSource(mCompilerParameters, mSource)
If mCompilerResults.Errors.Count > 0 Then
MessageBox.Show("عفوا... تعبير غير صالح", "خطأ")
Else
Dim mMethodInfo As Reflection.MethodInfo = mCompilerResults.CompiledAssembly.GetType("mCompile").GetMethod("mCalculate")
Return Convert.ToDouble(mMethodInfo.Invoke(Nothing, Nothing))
End If
End FunctionEnd Class