473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

second opinion

hey all,
i could have comma-separated values in a string
let's say: "4005","3","Updated" or really it can be individual strings it
doesn't matter.

what's the quickest or best way to get into this form:

"[field1]='4005' AND ([field2]='3' OR [field2]='Updated')"

thanks,
rodchar
Nov 19 '05 #1
4 990
Questions:

1) Are you always going to having only three values, or can you have more?
2) Will the desired format always be the same (that is with an AND and OR)
or will this be determined at runtime?
3) Will the field names always be "field1", "field2", ..., "fieldn"?

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
hey all,
i could have comma-separated values in a string
let's say: "4005","3","Updated" or really it can be individual strings it
doesn't matter.

what's the quickest or best way to get into this form:

"[field1]='4005' AND ([field2]='3' OR [field2]='Updated')"

thanks,
rodchar

Nov 19 '05 #2
"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
i could have comma-separated values in a string
let's say: "4005","3","Updated" or really it can be individual strings it
doesn't matter.

what's the quickest or best way to get into this form:

"[field1]='4005' AND ([field2]='3' OR [field2]='Updated')"


1) Are there always three elements in the string - could there be fewer or
more?

2) Are [field1], [field2] and [field3] actual column names in a data table,
or are they themselves variables?

3) Is it always [field1] AND ([field2] OR [field2])?

If so, I'd suggest using the Split() function to parse the string into an
array, then maybe using StringBuilder to create your string output.
Nov 19 '05 #3
> 1) Are you always going to having only three values, or can you have more?
it will vary.
2) Will the desired format always be the same (that is with an AND and OR)
or will this be determined at runtime? i'm just trying to build this as part of my where clause of my sqlCmd.Text.
3) Will the field names always be "field1", "field2", ..., "fieldn"? no.

rodchar.

"Peter Rilling" wrote:
Questions:

1) Are you always going to having only three values, or can you have more?
2) Will the desired format always be the same (that is with an AND and OR)
or will this be determined at runtime?
3) Will the field names always be "field1", "field2", ..., "fieldn"?

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
hey all,
i could have comma-separated values in a string
let's say: "4005","3","Updated" or really it can be individual strings it
doesn't matter.

what's the quickest or best way to get into this form:

"[field1]='4005' AND ([field2]='3' OR [field2]='Updated')"

thanks,
rodchar


Nov 19 '05 #4
You actually have more than one issue here, one of which you don't seem to
be aware of. Let me deal with the one you know about first:

It is important to define your terms when asking a question! Take time to
explain fully what you're talking about, in order to get the best answer in
the least amount of questions. "[field1]" could refer to a form field, a
field in a class, or almost anything else you want to name "[field1]".

Also, as we are unaware of the context in which you're doing this, we can
only answer the question as generally as you have asked it. I'll try to
cover all the bases, but you'll get more answers by making our work easier!
;-)

You're apparently talking about a conditional statement, such as

If ([field1]='4005' AND ([field2]='3' OR [field2]='Updated') Then...

Now, you're comparing 3 "things" with 3 literal strings (I hope). These 3
"things" are apparently tied to only ONE EACH of the literal strings you're
comparing them to. These 3 "things" are apparently not in an array, or a
collection. If these statements are all correct, there is a design
consideration you should take into account. Linking un-linked "things" to
linked "things" is not good design. It implicitly links the un-linked
"things" together, by virtue of the fact that they are all individually
linked to a "thing" in a group of linked "things." This makes your code
design less extensible, and confusing to anyone that works on that code in
the future (you, for example, say, 6 months from now).

A good rule of thumb is, do not relate things that are unrelated.
Conversely, relate things that ARE related. If, for example, you have a
Collection of some type, and you want to validate the members of that
Collection to a group of literal strings, it might be wise to put the
strings into a StringCollection, which has the same dimensions as the
Collection it is linked to. A Collection is mutable; that is, its size can
change. So, linking a Collection to an array is a bad idea; linking a
Collection to a Collection is a good idea; linking an array to an array is a
good idea.

Also, if you link a Collection to a Collection, all methods which operate on
the one should also operate on the other, in order to keep them
synchronized, having the same number of members, for example. The same would
go with arrays.

Now, as to the issue which you are unaware of:

Assuming again, that you are evaluating a condition of some sort (it's so
hard to tell from VB, as "=" and "=" can mean two different things, but one
can glean from the context, just as the compiler does!), let's say that your
fragment is part of an If statment, for the sake of this discussion:

If ([field1]='4005' AND ([field2]='3' OR [field2]='Updated') Then...

Note that the condition as stated is ambiguous. Do you mean

If BOTH [field1] is equal to '4005' AND [field2] is equal to '3' OR ONLY
[field2] is equal to 'Updated" regardless of the values of [field1] and
[field2] Then...

OR do you mean

If BOTH [field1] is equal to '4005' AND [field2] is equal to '3' or is equal
to 'Updated', but not any other value than '3' or 'Updated' then...

In the first case, BOTH [field1] MUST BE equal to '4005' AND [field2] MUST
BE equal to '3'. However, if [field2] is equal to 'Updated' it doesn't
matter what [field1] is equal to. If [field1] is equal to anything other
than '4005' the statement evaluates to false, unless, and only if field2 is
equal to 'Updated'. If [field1] is equal to '4004' and [field2] is equal to
'3' the statement evaluates to false.

In the second case, [field1] MUST BE equal to '4005'. However, if [field2]
is equal to '3' OR field2 is equal to 'Updated' is doesn't matter what
[field1] is equal to. If [field1] is equal to anything other than '4005' the
statement evaluates to false, unless [field2] is equal to EITHER '3' OR
'Updated'. If [field1] is equal to '4004' and [field2] is equal to '3' the
statement evaluates to true.

The program will use the default interpretation of this statement, but do
you know what the default is? I could look it up, but I prefer the easy way
(which is also easier on anyone working with this code in the future - you,
for example, say, 6 months from now):

If (([field1]='4005' AND ([field2]='3') OR [field2]='Updated') Then...

OR

If ([field1]='4005' AND (([field2]='3' OR [field2]='Updated')) Then...

The parentheses create logical groupings of conditions. Any time you use OR
in statement having multiple conditions, be aware of this pitfall.

And PLEASE, take time in the future to more completely explain what you're
talking about. I don't have all day for this stuff! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
I'd rather be a hammer than a nail.

"rodchar" <ro*****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
hey all,
i could have comma-separated values in a string
let's say: "4005","3","Updated" or really it can be individual strings it
doesn't matter.

what's the quickest or best way to get into this form:

"[field1]='4005' AND ([field2]='3' OR [field2]='Updated')"

thanks,
rodchar

Nov 19 '05 #5

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

Similar topics

10
by: Jurgen Oerlemans | last post by:
I have a code where I perform several actions on files. Between these actions I want to wait for 1 second. Or 2 seconds. How can I easily do this without using a timer? Jurgen
10
by: Jurgen Oerlemans | last post by:
I have a code where I perform several actions on files. Between these actions I want to wait for 1 second. Or 2 seconds. How can I easily do this without using a timer? Jurgen
10
by: Lyle Fairfield | last post by:
II first noticed this phenomenon in Access 2003. Simply stated it is: The second loop is faster than the first loop. That is if we test: Not (a Or b) against (Not a) And (Not b) in a loop of...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I make a 10 second delay? ----------------------------------------------------------------------- There...
1
by: DavidKrutsko | last post by:
Greetz, i just need a second hand opinion from other people.... say i have a function but the Key part is optional.... the way i have it layed out now is if (strcmp (argv, "-InFile /*or...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.