J
J Jones
I need to plug values into a condition like:
((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E > 59)
And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19 And F >
-1))
Where "E" and "F" have numeric values, and test if the condition is true.
There are 400 of these conditions and 10 variables "A" - "J".
What I thought was that I could build up an expression using the
stringbuilder in VB.Net. I have tried but I dont see how I can do it. Any
ideas. Here is some code i've been playing with.
Dim A, B, C, D, E, F, G, H, I, J As String
A = CStr(dt.Rows.Item(0).Item(0))
B = CStr(dt.Rows.Item(0).Item(1))
C = CStr(dt.Rows.Item(0).Item(2))
D = CStr(dt.Rows.Item(0).Item(3))
E = CStr(dt.Rows.Item(0).Item(4))
F = CStr(dt.Rows.Item(0).Item(5))
G = CStr(dt.Rows.Item(0).Item(6))
H = CStr(dt.Rows.Item(0).Item(7))
I = CStr(dt.Rows.Item(0).Item(8))
J = CStr(dt.Rows.Item(0).Item(9))
Dim xx As Boolean
Dim dc As DataColumn = ds.Tables(0).Columns.Add()
ds.Tables(0).Columns.Add("calcTrait")
For x = 0 To ds.Tables(0).Rows.Count - 1
Dim sb As New System.Text.StringBuilder
Dim condition As String =
CStr(ds.Tables(0).Rows(x).Item(0))
sb.Append(condition)
sb.Replace("And", "xxx")
sb.Replace("A", A)
sb.Replace("B", B)
sb.Replace("C", C)
sb.Replace("D", D)
sb.Replace("E", E)
sb.Replace("F", F)
sb.Replace("G", G)
sb.Replace("H", H)
sb.Replace("I", I)
sb.Replace("J", J)
sb.Replace("xxx", "And")
xx = CBool(sb.ToString)
If CBool(xx) Then
ds.Tables.Item(0).Rows(x).Item("calctrait") =
sb.ToString
End If
Next x
x = Nothing
((E <= 100 And E > 79) And (F <= 59 And F > 39)) Or ((E <= 79 And E > 59)
And (F <= 39 And F > 19)) Or ((E <= 59 And E > 39) And (F <= 19 And F >
-1))
Where "E" and "F" have numeric values, and test if the condition is true.
There are 400 of these conditions and 10 variables "A" - "J".
What I thought was that I could build up an expression using the
stringbuilder in VB.Net. I have tried but I dont see how I can do it. Any
ideas. Here is some code i've been playing with.
Dim A, B, C, D, E, F, G, H, I, J As String
A = CStr(dt.Rows.Item(0).Item(0))
B = CStr(dt.Rows.Item(0).Item(1))
C = CStr(dt.Rows.Item(0).Item(2))
D = CStr(dt.Rows.Item(0).Item(3))
E = CStr(dt.Rows.Item(0).Item(4))
F = CStr(dt.Rows.Item(0).Item(5))
G = CStr(dt.Rows.Item(0).Item(6))
H = CStr(dt.Rows.Item(0).Item(7))
I = CStr(dt.Rows.Item(0).Item(8))
J = CStr(dt.Rows.Item(0).Item(9))
Dim xx As Boolean
Dim dc As DataColumn = ds.Tables(0).Columns.Add()
ds.Tables(0).Columns.Add("calcTrait")
For x = 0 To ds.Tables(0).Rows.Count - 1
Dim sb As New System.Text.StringBuilder
Dim condition As String =
CStr(ds.Tables(0).Rows(x).Item(0))
sb.Append(condition)
sb.Replace("And", "xxx")
sb.Replace("A", A)
sb.Replace("B", B)
sb.Replace("C", C)
sb.Replace("D", D)
sb.Replace("E", E)
sb.Replace("F", F)
sb.Replace("G", G)
sb.Replace("H", H)
sb.Replace("I", I)
sb.Replace("J", J)
sb.Replace("xxx", "And")
xx = CBool(sb.ToString)
If CBool(xx) Then
ds.Tables.Item(0).Rows(x).Item("calctrait") =
sb.ToString
End If
Next x
x = Nothing