Saturday, 31 August 2013

How to convert a string into a conditional expression [on hold]

How to convert a string into a conditional expression [on hold]

Forgive me if this has already been asked, I looked and I couldn't find a
similar question anywhere. I need to convert a string that contains
conditional statements, sometimes nested inside one another into visual
basic code .
The following are examples of strings as they are stored in my db
1) If ([3] ='M' AND [4] ='S' AND [5]>=1000 : "OK"; "VIP")
2) If ([3] ='M' AND [4] ='S' AND [5]>=1000 : "OK") Else "VIP"
1) If ([3] = 'M' AND [4] = 'S' AND [5]>=1000 : 20/100 * [5]; 500)
2) If ([3] = 'M' AND [4] = 'S' AND [5]>=1000 : 20/100 * [5]) Else 500
1)If ([1] >=60 : 50; If ([1]>=50 : 40; If ([1]>=40 : 30; If([1]>=30 :
20;0))))
2) If ([1] >=60 : 50) Else If ([1]>=50 : 40) Else If ([1]>=40 : 30)
Else If ([1]>=30 : 20) Else 0
I know that using CodeDomProvider I can compile and run code in any .net
language , but before I do that, I need to have a string formatted in a
way the compiler can understand it, in other words I need that an input
string like this
If ([1] >=60 : 50; If ([1]>=50 : 40; If ([1]>=40 : 30; If([1]>=30 :
20;0))))
end up this way :
If ([1] >=60) Then
Return 50
Else If ([1]>=50)
Return 40
Else If ([1]>=40 )
Return 30
Else If([1]>=30 )
Return 20
Else
Return 0
End If
P.S. (1) and (2) are the same , being (2) just an alternative way of
recording the (1) expression The numbers inside square brackets are the
ID's of my variables
Any help would be appreciated. Thanks in advance!

No comments:

Post a Comment