473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

StringBuilder?

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
Nov 20 '05 #1
23 1739
J,

It isn't a string builder problem.. Use RegEx or a simple string

--
Kathleen Dollard
Microsoft MVP
Author "Code Generation in Microsoft .NET"
Nov 20 '05 #2
Ummm... can you give a slightly broader picture of what the actual goal is?
It seems possible that there may be a better alternative but it's hard to
tell from the listing. Are you trying to isolate rows from a database that
match hundreds of criteria?

Also as a sidenote... consider expressing the conditions slightly
differently e.g. (E > 79 And E <= 100) It tends to make it slightly more
obvious that E is supposed to be between that range.

Tom

"J Jones" <ji*@nospam.com> wrote..
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.

Nov 20 '05 #3
What you really need by the looks of it is the Eval statement which is no
longer supported by .NET ( To my knowledge ). I did see a very interesting
workaround to this using a JavaScript compiled into a DLL and declared in
VB.NET to use the eval.

If you do a search on google, you might find a way of doing this, its come
up a few times without a great solution. However, as tom leylan pointed out,
you may want to outline what it is you are actually trying to achieve we can
guess but it's a lot easier to be told explicitly.

Best Regards - OHM

O_H_M{at}BTInternet{dot}com


J Jones wrote:
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


--

Nov 20 '05 #4
* J Jones <ji*@nospam.com> scripsit:
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's the exact problem?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
So I have XML returned from SQL Server via a Stored Procedure. I then
transformed the XML string into a datatable. There Are 2 Columns in the
datatable: "condition" and "note". the "condition" column holds strings
like:

A < -10 And B > 0 And C > 0 And D > 0 And E > 10 And F > 10 And G > 0 And
H > 0 And I > 10 And J < -10

(I<= 59 And I > 14) And I > J And J < 20

((F <= 100 And F > 79) Or (F <= 79 And F > 59)) And G < -19 And H < -19

The "note" column holds strings like:

Although you are normally very busy and active there are areas that you
probably know you should handle or do things about that you don't handle
effectively.

His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target.

She tends to be over-analytical and sometimes put too much effort into
trying to figure out things that are not necessarily the most important.

I have another datatable holding calculated values for integers A - J
A=10
B=20
C=30
etc..

I want to use the "conditions" column select the "note" where the
"condition" is evaluated as being true.
Thanks

On Tue, 30 Dec 2003 15:44:38 +0000, J Jones wrote:
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

Nov 20 '05 #6
Good points Tom. To follow up
tell from the listing. Are you trying to isolate rows from a database that match hundreds of criteria?
Not having a fully informed knowledge of the methodologies for database
access in .Net, I may showing my hand earlier than I would normally. But
risking being flamed, I am going to comment the SQL query (if of-course
that is what the intention of the string

((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 > ....

is for - need some more information to help you J Jones). Having
considerable experience with Oracle databases, and programming in Java, C++,
and PL/SQL, I would not recommend repetitive execution or construction of
SQL statements in this manner. You will find the use of bind variables, for
repetitive queries with different values, far less expensive on the server.

Ie, something like this:

Dim stmt As System.Data.OleDb.OleDbCommand =
SupportClass.TransactionManager.manager.PrepareSta tement(conn,"SELECT
whatever FROM whereever WHERE (?<=100 and ?>79) AND (?<59 AND ?>39 AND
.....")
stmt.setString(1, aValue)
stmt.setString(2, anotherValue)
stmt.setString(3, anotherValue)

rather than putting aValue and anotherValue in the SQL statement per-se
(your original post J Jones).

The first execution of the PrepareStatement, your server will take the
expensive hit parsing it. The second and subsequent executions of the same
PrepareStatement, Oracle will check to see whether is already exists, and if
so use it saving considerable overhead. For a query of this
length/complexity, you risk thrashing the server. It may run okay for one or
two isolated database queries but it will certainly lack scalability. Go for
an alternative approach such as PrepareStatement.

The same databse server parsing argument can be applied to other databases.
I'm not sure on SQL Server but it's certainly the case for DB2.

Regards
Hexathioorthooxalate
"Tom Leylan" <ge*@iamtiredofspam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Ummm... can you give a slightly broader picture of what the actual goal is? It seems possible that there may be a better alternative but it's hard to
tell from the listing. Are you trying to isolate rows from a database that match hundreds of criteria?

Also as a sidenote... consider expressing the conditions slightly
differently e.g. (E > 79 And E <= 100) It tends to make it slightly more
obvious that E is supposed to be between that range.

Tom

"J Jones" <ji*@nospam.com> wrote..
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.


Nov 20 '05 #7
You might try a random number generator :-) Is this for telling fortunes?

Seriously though... step back one more level of description. You are making
it sound like the "A < -10 And B > 0" is some sort of natural occuring piece
of information that you simply have to work with. And it sounds like that
"string storage system" is the cause of the trouble you are having.

In English... do you have "paragraphs of text" and "criteria" which describe
various aspects of the paragraph? I assume the criteria correspond to your
letters and that the value indicates how much it corresponds? Any limit to
the range of values?

Instead of describing three "sort of like this" examples can you post a
single complete one?

"His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target."

What would I enter in a search that would end up matching this paragraph?

I don't mean to dig but I think people are having a problem answering your
question simply because there is little understanding of what you are trying
to accomplish. You might have set up the situation which makes it so hard
to create the SQL query.

Tom
"J Jones" <ji*@nospam.com> wrote...
So I have XML returned from SQL Server via a Stored Procedure. I then
transformed the XML string into a datatable. There Are 2 Columns in the
datatable: "condition" and "note". the "condition" column holds strings
like:

A < -10 And B > 0 And C > 0 And D > 0 And E > 10 And F > 10 And G > 0 And
H > 0 And I > 10 And J < -10

(I<= 59 And I > 14) And I > J And J < 20

((F <= 100 And F > 79) Or (F <= 79 And F > 59)) And G < -19 And H < -19

The "note" column holds strings like:

Although you are normally very busy and active there are areas that you
probably know you should handle or do things about that you don't handle
effectively.

His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target.

She tends to be over-analytical and sometimes put too much effort into
trying to figure out things that are not necessarily the most important.

I have another datatable holding calculated values for integers A - J
A=10
B=20
C=30
etc..

I want to use the "conditions" column select the "note" where the
"condition" is evaluated as being true.

Nov 20 '05 #8

Thanks Tom I'll try to make it clearer....

Seriously though... step back one more level of description. You are making
it sound like the "A < -10 And B > 0" is some sort of natural occuring piece
of information that you simply have to work with.
"A < -10 And B > 0" would be the search creiteria. ie. if A < -10 And B > 0
= TRUE then - - pull the text from that row.
In English... do you have "paragraphs of text" and "criteria" which describe
various aspects of the paragraph? I assume the criteria correspond to your
letters and that the value indicates how much it corresponds? Any limit to
the range of values? I have paragraphs of text that i want to display only if the criteria is
true i.e. if A < -10 And B > 0 = TRUE

(A could be any value from -100 to +120
B could be any value from -102 to +111)
Instead of describing three "sort of like this" examples can you post a
single complete one?

"His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target."

What would I enter in a search that would end up matching this paragraph?
My problem is that what I need to search is, for intstace A < -10 And B > 0
Where A gets replaced with the value of A from another table and B gets
replaced with the value of B from another table e.g. -99<-10 And -44 >0,
Obviously in this example the expression is not true so I wouldnt want to
return the text of this row.

I don't mean to dig but I think people are having a problem answering your
question simply because there is little understanding of what you are trying
to accomplish. You might have set up the situation which makes it so hard
to create the SQL query. Is an SQL query what I need?

Thanks
Jim "J Jones" <ji*@nospam.com> wrote...
So I have XML returned from SQL Server via a Stored Procedure. I then
transformed the XML string into a datatable. There Are 2 Columns in the
datatable: "condition" and "note". the "condition" column holds strings
like:

A < -10 And B > 0 And C > 0 And D > 0 And E > 10 And F > 10 And G > 0 And
H > 0 And I > 10 And J < -10

(I<= 59 And I > 14) And I > J And J < 20

((F <= 100 And F > 79) Or (F <= 79 And F > 59)) And G < -19 And H < -19

The "note" column holds strings like:

Although you are normally very busy and active there are areas that you
probably know you should handle or do things about that you don't handle
effectively.

His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target.

She tends to be over-analytical and sometimes put too much effort into
trying to figure out things that are not necessarily the most important.

I have another datatable holding calculated values for integers A - J
A=10
B=20
C=30
etc..

I want to use the "conditions" column select the "note" where the
"condition" is evaluated as being true.

Nov 20 '05 #9
J Jones,
I would use the DataTable.Select method to evaluate your condition column.

Something like:
Dim tableNotes As DataTable ' condition, note
Dim tableValues As DataTable ' A, B, C, D, E...

' tableResult contains the note rows that have a true condition
Dim tableResult As DataTable = tableNotes.Clone()

Dim exists() as DataRow

For Each row As DataRow in tableNotes.Rows
exists = tableValues.Select(DirectCast(row!condition, String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next

The tableResult table will have a row for each true condition. Instead of
"tableResult.ImportRow(row)" you could process the row at that time.

Note: David Sceppa's book "Microsoft ADO.NET - Core Reference" from MS
Press, is a very good tutorial on ADO.NET, plus its a good desk reference
once you know ADO.NET.

Hope this helps
Jay
"J Jones" <ji*@nospam.com> wrote in message
news:1g*****************************@40tude.net...
So I have XML returned from SQL Server via a Stored Procedure. I then
transformed the XML string into a datatable. There Are 2 Columns in the
datatable: "condition" and "note". the "condition" column holds strings
like:

A < -10 And B > 0 And C > 0 And D > 0 And E > 10 And F > 10 And G > 0 And
H > 0 And I > 10 And J < -10

(I<= 59 And I > 14) And I > J And J < 20

((F <= 100 And F > 79) Or (F <= 79 And F > 59)) And G < -19 And H < -19

The "note" column holds strings like:

Although you are normally very busy and active there are areas that you
probably know you should handle or do things about that you don't handle
effectively.

His high standards and demands are not always combined with correct
estimation of people and situations. This can lead him to be critical; he
gets stuck in handling details to "perfection" while missing the overall
target.

She tends to be over-analytical and sometimes put too much effort into
trying to figure out things that are not necessarily the most important.

I have another datatable holding calculated values for integers A - J
A=10
B=20
C=30
etc..

I want to use the "conditions" column select the "note" where the
"condition" is evaluated as being true.
Thanks

On Tue, 30 Dec 2003 15:44:38 +0000, J Jones wrote:
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

Nov 20 '05 #10
"J Jones" <ji*@nospam.com> wrote...
"A < -10 And B > 0" would be the search creiteria. ie. if A < -10 And B > 0 = TRUE then - - pull the text from that row.
That's good. And we can infer that the criteria can get fairly involved and
also that you created this criteria string right? And just to clarify if A
was only -9 then this paragraph doesn't qualify. And that would be because
it's A-ness (so to speak) is extremely low whereas it has positive B-ness?

Doesn't the description alone make you cringe? What could the quality of
"A" represent and couldn't this be represented in some other way? Not that
you have to, I'm not suggesting it is "wrong" simply fraught with the
potential for errors since it can barely be read and probably can't easily
be written.

Again I have no clue but "usually" (if I can use that term) the attributes
are assigned rather than a "matching criteria" and in that way some routine
can simply ask for the matching criteria.

In other words if you can assign this paragraphs "A-ness and B-ness" as
simple values A = -10 and B = 1 (for instance) then the query would decide
whether it wanted to see all the A's that were below zero or the B's that
were between 1 and 5. By adding simple attributes it would be possible to
"refine" the search. You could (for instance) ask to see a list of all that
met criteria "A <= 0" and your sample would appear along with 300 others...
then you could say heck, just show me the ones that also match "B > 3" and
if this had a B value of 1 it would be dropped from the list.
My problem is that what I need to search is, for intstace A < -10 And B > 0 Where A gets replaced with the value of A from another table and B gets
replaced with the value of B from another table e.g. -99<-10 And -44 >0,
Obviously in this example the expression is not true so I wouldnt want to
return the text of this row.
Not knowing what A and B represent it's hard to follow but I've never seen
anything like it which suggests it's an odd solution. I can't come with a
great example but it looks like you would be doing the equivalent of setting
up a search for a book title (let's say) by defining the criteria (in the
book) as:

title.contains( "T") or title.contains( "Th") or title.contains("The") ...
etc.

rather than simply identifying the book title (the actual attribute) and
letting a query somewhere decide if it wanted just "The Red Pony" or every
book title that starts with "T" or any book that contains the word "the".
Is an SQL query what I need?


If it can't be done through a SQL query there is a good chance that
something is up :-) There are problems where SQL isn't optimal but the
solution should probably be able to be expressed with SQL syntax. Again it
looks like an odd way to describe the matching criteria of a paragraph this
way. Who knows the problem could be such that there isn't any way but try
as I will I can't think of one.

How does a paragraph get selected on the basis of A being -10 or less? What
is that somebody looking for A = -9 would notice if this paragraph popped
up? Would they say "hey that's only -9 A-ness?" I didn't want a -13 A...
that's simply not enough A for me.

I'm afraid I still don't get it.
Tom

Nov 20 '05 #11
Ok Tom,
if I write:

Dim A,B,C As Integer
A = 10
B = 20
C = 30
If
A<B And B<100 And C<=30 = True
Then
Initalizedisplay()
Else
Giveup()

The above will Initalizedisplay(). Because the expression is true.
That is what is wanted.

My situation is:(example)
I have 3 varables declared as Integers
A = 10, B = 20, C = 30
And I have and expression in a datatable in a dataset
A<B And B<100 And C<=30

I import "A<B And B<100 And C<=30" as a string into a StringBuilder
and use StringBuilder.Replace to insert the values of A,B and C as string
values.
So what I have is 10<20 And 20<100 And 30<=30. but it is a string so I cant
evaluate it as true or false. That is the problem I have.


On Tue, 30 Dec 2003 15:38:06 -0500, Tom Leylan wrote:
"J Jones" <ji*@nospam.com> wrote...
"A < -10 And B > 0" would be the search creiteria. ie. if A < -10 And B >

0
= TRUE then - - pull the text from that row.


That's good. And we can infer that the criteria can get fairly involved and
also that you created this criteria string right? And just to clarify if A
was only -9 then this paragraph doesn't qualify. And that would be because
it's A-ness (so to speak) is extremely low whereas it has positive B-ness?

Doesn't the description alone make you cringe? What could the quality of
"A" represent and couldn't this be represented in some other way? Not that
you have to, I'm not suggesting it is "wrong" simply fraught with the
potential for errors since it can barely be read and probably can't easily
be written.

Again I have no clue but "usually" (if I can use that term) the attributes
are assigned rather than a "matching criteria" and in that way some routine
can simply ask for the matching criteria.

In other words if you can assign this paragraphs "A-ness and B-ness" as
simple values A = -10 and B = 1 (for instance) then the query would decide
whether it wanted to see all the A's that were below zero or the B's that
were between 1 and 5. By adding simple attributes it would be possible to
"refine" the search. You could (for instance) ask to see a list of all that
met criteria "A <= 0" and your sample would appear along with 300 others...
then you could say heck, just show me the ones that also match "B > 3" and
if this had a B value of 1 it would be dropped from the list.
My problem is that what I need to search is, for intstace A < -10 And B >

0
Where A gets replaced with the value of A from another table and B gets
replaced with the value of B from another table e.g. -99<-10 And -44 >0,
Obviously in this example the expression is not true so I wouldnt want to
return the text of this row.


Not knowing what A and B represent it's hard to follow but I've never seen
anything like it which suggests it's an odd solution. I can't come with a
great example but it looks like you would be doing the equivalent of setting
up a search for a book title (let's say) by defining the criteria (in the
book) as:

title.contains( "T") or title.contains( "Th") or title.contains("The") ...
etc.

rather than simply identifying the book title (the actual attribute) and
letting a query somewhere decide if it wanted just "The Red Pony" or every
book title that starts with "T" or any book that contains the word "the".
Is an SQL query what I need?


If it can't be done through a SQL query there is a good chance that
something is up :-) There are problems where SQL isn't optimal but the
solution should probably be able to be expressed with SQL syntax. Again it
looks like an odd way to describe the matching criteria of a paragraph this
way. Who knows the problem could be such that there isn't any way but try
as I will I can't think of one.

How does a paragraph get selected on the basis of A being -10 or less? What
is that somebody looking for A = -9 would notice if this paragraph popped
up? Would they say "hey that's only -9 A-ness?" I didn't want a -13 A...
that's simply not enough A for me.

I'm afraid I still don't get it.
Tom

Nov 20 '05 #12
J Jones,
So what I have is 10<20 And 20<100 And 30<=30. but it is a string so I cant evaluate it as true or false. That is the problem I have. Did you try the sample code I posted?

It will evaluates your condition string against your values table. Without
using a string builder or running an SQL statement against the server!

Of course we all may be missing what you are trying to accomplish.

Hope this helps
Jay
"J Jones" <ji*@nospam.com> wrote in message
news:s3*****************************@40tude.net... Ok Tom,
if I write:

Dim A,B,C As Integer
A = 10
B = 20
C = 30
If
A<B And B<100 And C<=30 = True
Then
Initalizedisplay()
Else
Giveup()

The above will Initalizedisplay(). Because the expression is true.
That is what is wanted.

My situation is:(example)
I have 3 varables declared as Integers
A = 10, B = 20, C = 30
And I have and expression in a datatable in a dataset
A<B And B<100 And C<=30

I import "A<B And B<100 And C<=30" as a string into a StringBuilder
and use StringBuilder.Replace to insert the values of A,B and C as string
values.
So what I have is 10<20 And 20<100 And 30<=30. but it is a string so I cant evaluate it as true or false. That is the problem I have.


On Tue, 30 Dec 2003 15:38:06 -0500, Tom Leylan wrote:
"J Jones" <ji*@nospam.com> wrote...
"A < -10 And B > 0" would be the search creiteria. ie. if A < -10 And B
0
= TRUE then - - pull the text from that row.


That's good. And we can infer that the criteria can get fairly involved and also that you created this criteria string right? And just to clarify if A was only -9 then this paragraph doesn't qualify. And that would be because it's A-ness (so to speak) is extremely low whereas it has positive B-ness?
Doesn't the description alone make you cringe? What could the quality of "A" represent and couldn't this be represented in some other way? Not that you have to, I'm not suggesting it is "wrong" simply fraught with the
potential for errors since it can barely be read and probably can't easily be written.

Again I have no clue but "usually" (if I can use that term) the attributes are assigned rather than a "matching criteria" and in that way some routine can simply ask for the matching criteria.

In other words if you can assign this paragraphs "A-ness and B-ness" as
simple values A = -10 and B = 1 (for instance) then the query would decide whether it wanted to see all the A's that were below zero or the B's that were between 1 and 5. By adding simple attributes it would be possible to "refine" the search. You could (for instance) ask to see a list of all that met criteria "A <= 0" and your sample would appear along with 300 others... then you could say heck, just show me the ones that also match "B > 3" and if this had a B value of 1 it would be dropped from the list.
My problem is that what I need to search is, for intstace A < -10 And B
0
Where A gets replaced with the value of A from another table and B gets
replaced with the value of B from another table e.g. -99<-10 And -44

0, Obviously in this example the expression is not true so I wouldnt want to return the text of this row.


Not knowing what A and B represent it's hard to follow but I've never

seen anything like it which suggests it's an odd solution. I can't come with a great example but it looks like you would be doing the equivalent of setting up a search for a book title (let's say) by defining the criteria (in the book) as:

title.contains( "T") or title.contains( "Th") or title.contains("The") .... etc.

rather than simply identifying the book title (the actual attribute) and
letting a query somewhere decide if it wanted just "The Red Pony" or every book title that starts with "T" or any book that contains the word "the".
Is an SQL query what I need?


If it can't be done through a SQL query there is a good chance that
something is up :-) There are problems where SQL isn't optimal but the
solution should probably be able to be expressed with SQL syntax. Again it looks like an odd way to describe the matching criteria of a paragraph this way. Who knows the problem could be such that there isn't any way but try as I will I can't think of one.

How does a paragraph get selected on the basis of A being -10 or less? What is that somebody looking for A = -9 would notice if this paragraph popped up? Would they say "hey that's only -9 A-ness?" I didn't want a -13 A... that's simply not enough A for me.

I'm afraid I still don't get it.
Tom

Nov 20 '05 #13
"J Jones" <ji*@nospam.com> wrote...
So what I have is 10<20 And 20<100 And 30<=30. but it is a string so I cant evaluate it as true or false. That is the problem I have.


Okay I've got it... Jay presented one solution (I didn't try it) but I did
search around and you won't believe what I found :-) And it works!

The instructions are presented here. If you follow them you will get the
results demonstrated. Note that your copy of jsc (the jscript compiler) may
not be in the folder referenced in the article.
http://dbforums.com/arch/219/2002/12/578053

To get it to behave more like you want you have to modify the example to
take the parameters A, B and C (as integers) and pass them along. Then you
can reference the variables by name in your expression.

So for instance I made the following modification:

class JScriptEval {
function Evaluate(evalString : String, a : int, b : int, c: int)
{ return eval(evalString); }
}

Which lets me pass along three integer values. Remember you have to
reference the variable names in the string as they are named in the Evaluate
function.

Dim a As Integer = 3
Dim j As New JScriptEval
Dim s1 As String = "a + 2 * 3"
MsgBox(j.Evaluate(s1, a, 0, 0))

So you would write:

Dim test As Integer = 3
Dim me As Integer = 5
Dim j As New JScriptEval
Dim s1 As String = "a + 2 * c"
MsgBox(j.Evaluate(s1, test, 0, me))

so long as the string uses the letter names. Probably a good idea to use
the same names to keep things straight however.

Interesting huh?
Tom

Nov 20 '05 #14
Ahemmm, Did I not mention this at the start of this thread ?

Regards - OHM

Tom Leylan wrote:
"J Jones" <ji*@nospam.com> wrote...
So what I have is 10<20 And 20<100 And 30<=30. but it is a string so
I cant evaluate it as true or false. That is the problem I have.


Okay I've got it... Jay presented one solution (I didn't try it) but
I did search around and you won't believe what I found :-) And it
works!

The instructions are presented here. If you follow them you will get
the results demonstrated. Note that your copy of jsc (the jscript
compiler) may not be in the folder referenced in the article.
http://dbforums.com/arch/219/2002/12/578053

To get it to behave more like you want you have to modify the example
to take the parameters A, B and C (as integers) and pass them along.
Then you can reference the variables by name in your expression.

So for instance I made the following modification:

class JScriptEval {
function Evaluate(evalString : String, a : int, b : int, c: int)
{ return eval(evalString); }
}

Which lets me pass along three integer values. Remember you have to
reference the variable names in the string as they are named in the
Evaluate function.

Dim a As Integer = 3
Dim j As New JScriptEval
Dim s1 As String = "a + 2 * 3"
MsgBox(j.Evaluate(s1, a, 0, 0))

So you would write:

Dim test As Integer = 3
Dim me As Integer = 5
Dim j As New JScriptEval
Dim s1 As String = "a + 2 * c"
MsgBox(j.Evaluate(s1, test, 0, me))

so long as the string uses the letter names. Probably a good idea to
use the same names to keep things straight however.

Interesting huh?
Tom


--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com
Nov 20 '05 #15
Sorry about that... I must have scanned it... perhaps subconsciously that
was my motivation to do the search. So "as One Handed Man mentioned"...

It might be best if I leave the answers in 2004 to the experts!

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Ahemmm, Did I not mention this at the start of this thread ?

Regards - OHM

Nov 20 '05 #16
Thanks for all your effort. I followede the instructions and I got as far
as adding the references before my app. fell apart:-( now I have removed
the two references but my app wont work because it says it doesnt have
references to the things that I'm sure it did have references to - like
system, system.xmland the function overrides are throwing up errors.. ANY
IDEAS?

On Tue, 30 Dec 2003 18:27:53 -0500, Tom Leylan wrote:
Sorry about that... I must have scanned it... perhaps subconsciously that
was my motivation to do the search. So "as One Handed Man mentioned"...

It might be best if I leave the answers in 2004 to the experts!

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Ahemmm, Did I not mention this at the start of this thread ?

Regards - OHM

Nov 20 '05 #17
All is well with my app. again.Thanks to everyone for the help.
Jim

On Wed, 31 Dec 2003 00:26:09 +0000, J Jones wrote:
Thanks for all your effort. I followede the instructions and I got as far
as adding the references before my app. fell apart:-( now I have removed
the two references but my app wont work because it says it doesnt have
references to the things that I'm sure it did have references to - like
system, system.xmland the function overrides are throwing up errors.. ANY
IDEAS?

On Tue, 30 Dec 2003 18:27:53 -0500, Tom Leylan wrote:
Sorry about that... I must have scanned it... perhaps subconsciously that
was my motivation to do the search. So "as One Handed Man mentioned"...

It might be best if I leave the answers in 2004 to the experts!

"One Handed Man [ OHM# ]" <O_H_M{at}BTInternet{dot}com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Ahemmm, Did I not mention this at the start of this thread ?

Regards - OHM

Nov 20 '05 #18

Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?

Private Sub Res()

Dim oBusinessLogic As New SurveyAdminLogic.BusinessLogic
Dim sXML1 As String
Dim sXML As String
Dim iReturn As Integer
Dim intResultIndex As Integer = CInt(txtSession.Text)

Try
sXML1 = oBusinessLogic.GetTraits(iReturn)
sXML = oBusinessLogic.GetScores(intResultIndex, iReturn)
Catch ex As Exception

End Try

oBusinessLogic = Nothing
Select Case iReturn

Case RETURN_SUCCESS
Dim dsValues As New DataSet
Dim dsNotes As New DataSet
Dim rValues As New System.IO.StringReader(sXML)
Dim rNotes As New System.IO.StringReader(sXML1)

Dim dtValues As New DataTable
Dim drValues As DataRow = dtValues.NewRow
Dim x As Integer = 0

dsValues.ReadXml(rValues)
dsNotes.ReadXml(rNotes)

dsValues.Tables.Add(dtValues)

While x < dsValues.Tables.Item(0).Rows.Count - 1
For Each row As DataRow In
dsValues.Tables.Item("Result").Rows

dtValues.Columns.Add(CStr(dsValues.Tables.Item(0). Rows.Item(x).Item(0)),
System.Type.GetType("System.Int32"))
x = x + 1
Next
End While
x = Nothing

dtValues.Rows.Add(drValues)

For x = 0 To dsValues.Tables.Item(0).Rows.Count - 1
dtValues.Rows.Item(0).Item(x) =
CInt(dsValues.Tables.Item(0).Rows.Item(x).Item(1))
Next

' tableResult contains the note rows that have a true
condition
Dim tableResult As DataTable = dsNotes.Tables(0).Clone()

Dim exists() As DataRow

For Each row As DataRow In dsNotes.Tables(0).Rows
exists = dtValues.Select(DirectCast(row!condition,
String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next
DataGrid1.DataSource = tableResult
DataGrid1.DataBind()
DataGrid1.Visible = True

End Select
End Sub

On Tue, 30 Dec 2003 14:12:47 -0600, Jay B. Harlow [MVP - Outlook] wrote:
J Jones,
I would use the DataTable.Select method to evaluate your condition column.

Nov 20 '05 #19
J Jones,
Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?
Which line do you get that error? Is it at run time or compile time?

If you are getting it on the following line at run time:
exists = dtValues.Select(DirectCast(row!condition, String))
Then it sounds like you have a badly formed condition expression in your
table. The three you posted worked fine.

Remember that "row!condition" is short for "row.Item("condition")" where
"condition" is the name of the field in the DataTable.

For the proper syntax on the expression see:

http://msdn.microsoft.com/library/de...ssiontopic.asp

You may want to put the dtValues.Select itself in its own Try Catch, and
display the value of the "condition" field in the catch block, just to make
sure the syntax is correct... Alternatively you could add a column to
dsNotes.Tables(0) that you update in the catch block around dtValues.Select
to indicate a syntax error for that row...

Something like:

Try
row!ValidSyntax = True exists = dtValues.Select(DirectCast(row!condition, String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If Catch ex As Exception
row!ValidSyntax = False
End Try

Then when you are done the dsNotes.Tables(0) will have a column indicating
if the condition was valid or not...

Hope this helps
Jay

"J Jones" <ji*@nospam.com> wrote in message
news:4m*****************************@40tude.net...
Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?

Private Sub Res()

Dim oBusinessLogic As New SurveyAdminLogic.BusinessLogic
Dim sXML1 As String
Dim sXML As String
Dim iReturn As Integer
Dim intResultIndex As Integer = CInt(txtSession.Text)

Try
sXML1 = oBusinessLogic.GetTraits(iReturn)
sXML = oBusinessLogic.GetScores(intResultIndex, iReturn)
Catch ex As Exception

End Try

oBusinessLogic = Nothing
Select Case iReturn

Case RETURN_SUCCESS
Dim dsValues As New DataSet
Dim dsNotes As New DataSet
Dim rValues As New System.IO.StringReader(sXML)
Dim rNotes As New System.IO.StringReader(sXML1)

Dim dtValues As New DataTable
Dim drValues As DataRow = dtValues.NewRow
Dim x As Integer = 0

dsValues.ReadXml(rValues)
dsNotes.ReadXml(rNotes)

dsValues.Tables.Add(dtValues)

While x < dsValues.Tables.Item(0).Rows.Count - 1
For Each row As DataRow In
dsValues.Tables.Item("Result").Rows

dtValues.Columns.Add(CStr(dsValues.Tables.Item(0). Rows.Item(x).Item(0)),
System.Type.GetType("System.Int32"))
x = x + 1
Next
End While
x = Nothing

dtValues.Rows.Add(drValues)

For x = 0 To dsValues.Tables.Item(0).Rows.Count - 1
dtValues.Rows.Item(0).Item(x) =
CInt(dsValues.Tables.Item(0).Rows.Item(x).Item(1))
Next

' tableResult contains the note rows that have a true
condition
Dim tableResult As DataTable = dsNotes.Tables(0).Clone()

Dim exists() As DataRow

For Each row As DataRow In dsNotes.Tables(0).Rows
exists = dtValues.Select(DirectCast(row!condition,
String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next
DataGrid1.DataSource = tableResult
DataGrid1.DataBind()
DataGrid1.Visible = True

End Select
End Sub

On Tue, 30 Dec 2003 14:12:47 -0600, Jay B. Harlow [MVP - Outlook] wrote:
J Jones,
I would use the DataTable.Select method to evaluate your condition

column.
Nov 20 '05 #20
J Jones,
Thinking about it, it may make more sense to have the syntax errors in your
result table or in an errors table, so that you can display them to the
user. Also I would consider logging the syntax errors, depending on who is
responsible for maintaining the Notes table in your SQL Server...

In which case you would need an ImportRow in the catch handler also.
Optionally setting the valid syntax field, something like:

Try
row!ValidSyntax = True
exists = dtValues.Select(DirectCast(row!condition, String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If Catch ex As Exception
row!ValidSyntax = False tableResult.ImportRow(row) End Try

In the above example I am assuming that the dsNotes.Tables(0) datatable will
be discarded and modifying it will not cause problems, if this is not true,
then you will need to change the above code appropriately...

A word of caution, my sample code will treat problems with
"tableResult.ImportRow" as syntax errors, which may not be what you want...
I would consider modifying the code to be a little more robust (only catch
errors on the Select itself! however watch for reusing the exists variable
from the previous row ;-))

Hope this helps
Jay

"J Jones" <ji*@nospam.com> wrote in message
news:4m*****************************@40tude.net...
Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?

Private Sub Res()

Dim oBusinessLogic As New SurveyAdminLogic.BusinessLogic
Dim sXML1 As String
Dim sXML As String
Dim iReturn As Integer
Dim intResultIndex As Integer = CInt(txtSession.Text)

Try
sXML1 = oBusinessLogic.GetTraits(iReturn)
sXML = oBusinessLogic.GetScores(intResultIndex, iReturn)
Catch ex As Exception

End Try

oBusinessLogic = Nothing
Select Case iReturn

Case RETURN_SUCCESS
Dim dsValues As New DataSet
Dim dsNotes As New DataSet
Dim rValues As New System.IO.StringReader(sXML)
Dim rNotes As New System.IO.StringReader(sXML1)

Dim dtValues As New DataTable
Dim drValues As DataRow = dtValues.NewRow
Dim x As Integer = 0

dsValues.ReadXml(rValues)
dsNotes.ReadXml(rNotes)

dsValues.Tables.Add(dtValues)

While x < dsValues.Tables.Item(0).Rows.Count - 1
For Each row As DataRow In
dsValues.Tables.Item("Result").Rows

dtValues.Columns.Add(CStr(dsValues.Tables.Item(0). Rows.Item(x).Item(0)),
System.Type.GetType("System.Int32"))
x = x + 1
Next
End While
x = Nothing

dtValues.Rows.Add(drValues)

For x = 0 To dsValues.Tables.Item(0).Rows.Count - 1
dtValues.Rows.Item(0).Item(x) =
CInt(dsValues.Tables.Item(0).Rows.Item(x).Item(1))
Next

' tableResult contains the note rows that have a true
condition
Dim tableResult As DataTable = dsNotes.Tables(0).Clone()

Dim exists() As DataRow

For Each row As DataRow In dsNotes.Tables(0).Rows
exists = dtValues.Select(DirectCast(row!condition,
String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next
DataGrid1.DataSource = tableResult
DataGrid1.DataBind()
DataGrid1.Visible = True

End Select
End Sub

On Tue, 30 Dec 2003 14:12:47 -0600, Jay B. Harlow [MVP - Outlook] wrote:
J Jones,
I would use the DataTable.Select method to evaluate your condition

column.
Nov 20 '05 #21
I could be wrong but I didn't know you could build a boolean statement and
then do an Eval on it. I saw an interesting article on CodeProject that
dealt with creating a Eval statement that really seemed to work.

http://codeproject.com/dotnet/evaluator.asp
"J Jones" <ji*@nospam.com> wrote in message
news:1h*******************************@40tude.net. ..
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

Nov 20 '05 #22
FANTASTIC!!!!! Thanks SooOO Much..
O)ne day I'm sure I'll figure out how it works. For now I'm Just glad it
does.

Jim
On Wed, 31 Dec 2003 08:41:02 -0600, Jay B. Harlow [MVP - Outlook] wrote:
J Jones,
Thinking about it, it may make more sense to have the syntax errors in your
result table or in an errors table, so that you can display them to the
user. Also I would consider logging the syntax errors, depending on who is
responsible for maintaining the Notes table in your SQL Server...

In which case you would need an ImportRow in the catch handler also.
Optionally setting the valid syntax field, something like:

Try
row!ValidSyntax = True
exists = dtValues.Select(DirectCast(row!condition, String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If

Catch ex As Exception
row!ValidSyntax = False
tableResult.ImportRow(row)

End Try

In the above example I am assuming that the dsNotes.Tables(0) datatable will
be discarded and modifying it will not cause problems, if this is not true,
then you will need to change the above code appropriately...

A word of caution, my sample code will treat problems with
"tableResult.ImportRow" as syntax errors, which may not be what you want...
I would consider modifying the code to be a little more robust (only catch
errors on the Select itself! however watch for reusing the exists variable
from the previous row ;-))

Hope this helps
Jay

"J Jones" <ji*@nospam.com> wrote in message
news:4m*****************************@40tude.net...

Thanks Jay, I'm trying you code but am not having much luck.
I've had to play around with it a bit to fit it into my code and I get:
Syntax error: Missing operand after '0' operator.
I've posted the entire Sub, Maybe you can see what I've done wrong?

Private Sub Res()

Dim oBusinessLogic As New SurveyAdminLogic.BusinessLogic
Dim sXML1 As String
Dim sXML As String
Dim iReturn As Integer
Dim intResultIndex As Integer = CInt(txtSession.Text)

Try
sXML1 = oBusinessLogic.GetTraits(iReturn)
sXML = oBusinessLogic.GetScores(intResultIndex, iReturn)
Catch ex As Exception

End Try

oBusinessLogic = Nothing
Select Case iReturn

Case RETURN_SUCCESS
Dim dsValues As New DataSet
Dim dsNotes As New DataSet
Dim rValues As New System.IO.StringReader(sXML)
Dim rNotes As New System.IO.StringReader(sXML1)

Dim dtValues As New DataTable
Dim drValues As DataRow = dtValues.NewRow
Dim x As Integer = 0

dsValues.ReadXml(rValues)
dsNotes.ReadXml(rNotes)

dsValues.Tables.Add(dtValues)

While x < dsValues.Tables.Item(0).Rows.Count - 1
For Each row As DataRow In
dsValues.Tables.Item("Result").Rows

dtValues.Columns.Add(CStr(dsValues.Tables.Item(0). Rows.Item(x).Item(0)),
System.Type.GetType("System.Int32"))
x = x + 1
Next
End While
x = Nothing

dtValues.Rows.Add(drValues)

For x = 0 To dsValues.Tables.Item(0).Rows.Count - 1
dtValues.Rows.Item(0).Item(x) =
CInt(dsValues.Tables.Item(0).Rows.Item(x).Item(1))
Next

' tableResult contains the note rows that have a true
condition
Dim tableResult As DataTable = dsNotes.Tables(0).Clone()

Dim exists() As DataRow

For Each row As DataRow In dsNotes.Tables(0).Rows
exists = dtValues.Select(DirectCast(row!condition,
String))
If exists.Length > 0 Then
tableResult.ImportRow(row)
End If
Next
DataGrid1.DataSource = tableResult
DataGrid1.DataBind()
DataGrid1.Visible = True

End Select
End Sub

On Tue, 30 Dec 2003 14:12:47 -0600, Jay B. Harlow [MVP - Outlook] wrote:
J Jones,
I would use the DataTable.Select method to evaluate your condition

column.

Nov 20 '05 #23
Jim,
The DataTable.Select function runs a 'query' against a datatable, it returns
an array of rows that match the criteria that you send in.

The Select function always returns an array, however if no rows match the
criteria an array with no rows is returned.

It just happens that your criteria is a column in another dataset.

David Sceppa's book I mention earlier explains ADO.NET (& DataTable.Select)
rather well!

Hope this helps
Jay

"J Jones" <ji*@nospam.com> wrote in message
news:18******************************@40tude.net.. .
FANTASTIC!!!!! Thanks SooOO Much..
O)ne day I'm sure I'll figure out how it works. For now I'm Just glad it
does.

Jim

<<snip>>
Nov 20 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
20
by: Alvin Bruney | last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the results. Here are the numbers: Total # queries 3747 Time in Milliseconds StringBuilder: String...
0
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR ...
11
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the...
2
by: Peter | last post by:
Hi, A newbie question .. I want to use an array of length 4 while each array element is a string of 40 chars. I typed .. StringBuilder title = new StringBuilder(40);
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
12
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a...
2
by: m00nm0nkey | last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is appending 50,000 lines from the collection to a stringbuilder, and then writing that entire stringbuilder to a file. ...
5
by: pantagruel | last post by:
Hi, It is generally stated that stringbuilder should be used instead of just concatenating strings with the plus operator. That's fine enough what I'm wondering in cases I have: String S =...
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.