Home > Archive > Visual Basic > March 2004 > Re: Evaulation Boolean Expression
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Evaulation Boolean Expression
|
|
| Larry Serflaten 2004-03-30, 9:30 am |
|
"Darren Rhymer" <darren.rhymer@scisys.co.uk> wrote
>
> Im writing code in VB6 that needs to evaluatea string expression into a boolean.
>
<.>
> When I have found the next question to ask I have to determine if that question can be asked. I search another db table with a
questionId and a condition table.
>
> My condition for question 27 is "23,=true,OR,25,=true" meaning that either question 23 or 25 must have been answered true for
this question to ask.
How did you arrive at that format to denote conditions?
> I've replaced the values so I now have:
Why did you replace anything? Why isn't the data in a format you can use?
Sometimes you have to store data in a format that makes it easy to store,
sometimes you have to use a format that is easy for humans to read, and
still other times, you need to use data that makes for easy programming code.
The developer has to choose the right balance when deciding what to store.
The point is, before you settled on the 23,=true, format, you should have
already looked at what it would take to turn that into data the program can
use. Since you are posting a question about it, I would suggest you take a
look back at why you are using that format, if it can't be easily used, or, at
least difficult for you to use....
In other words, you really haven't finshed your design phase yet, and
rather than lead you on into a quagmire of string parsing, I would suggest
you take a hard look at the format and decide what it should be if you
wanted to be able to easily evaluate any conditions. When you have
that figured out, then perhaps you can change the format accordingly,
and move on from there....
LFS
| |
| Tony Proctor 2004-03-30, 9:30 am |
| You could try the scripting control
' Replace commas with spaces
sExpr = Replace(sExpr, ",", " ")
' Evaluate the condition
Debug.Print ScriptControl1.Eval(sExpr)
Tony Proctor
"Darren Rhymer" <darren.rhymer@scisys.co.uk> wrote in message
news:D7C41AEE-3770-4F62-9462-2FFEC4C2EEAE@microsoft.com...
> Hi all
>
> Im writing code in VB6 that needs to evaluatea string expression into a
boolean.
>
> The code loops round a collection of questions asking the user one
question at a time. When a question is answered I search a db table for the
question Id along with the answer to find what the next question to ask
should be.
>
> When I have found the next question to ask I have to determine if that
question can be asked. I search another db table with a questionId and a
condition table.
>
> My condition for question 27 is "23,=true,OR,25,=true" meaning that
either question 23 or 25 must have been answered true for this question to
ask.
>
> I've replaced the values so I now have:
>
> "true,=true,OR,false,=true" but how do I evaulaute it? I only ask the
question if the result is true.
>
> Thanks for any help
>
> Darren Rhymer
>
| |
| Rick Rothstein 2004-03-30, 10:30 am |
| > Im writing code in VB6 that needs to evaluatea string expression into a
boolean.
>
> The code loops round a collection of questions asking the user one
question at a time. When a question is answered I search a db table for the
question Id along with the answer to find what the next question to ask
should be.
>
> When I have found the next question to ask I have to determine if that
question can be asked. I search another db table with a questionId and a
condition table.
>
> My condition for question 27 is "23,=true,OR,25,=true" meaning that
either question 23 or 25 must have been answered true for this question to
ask.
>
> I've replaced the values so I now have:
>
> "true,=true,OR,false,=true" but how do I evaulaute it? I only ask the
question if the result is true.
Before even attempting to answer the question you asked, I think you need to
tell us if the example you have given is as complex as it will get. For
example, could there be a 3rd question OR'ed into the list? What about
having two or more questions AND'ed together, is that a possibility? If so,
could AND's and OR's be mixed within the same conditional clause (such as
23,=true,OR,25,=true,AND,27,=true"? If, again, this is so, are they
evaluated left-to-right or can there evaluation order be changed by using
parentheses to group certain parts? Is "=" the only logical operator that
can be used? Remember, the more *stuff* you add to the mix, the harder it
might be to come up with a solution.
Rick - MVP
| |
| Larry Serflaten 2004-03-30, 12:30 pm |
|
"Darren Rhymer" <anonymous@discussions.microsoft.com> wrote
>
> but I changed it as I was hoping this would make it easy for me to evaulate/calculate.
>
<...>
> So what would your design be? Ive been through a few designs and they all seem v tricky when you start adding () and additional
conditions.
As Rick points out, we don't have enough information to decide what would work.
You need to describe the specifics of what needs to be accounted for.
A few questions that need to be answered would be;
Is there only one simple expression : AA Or CC
Or, must it be complex: (AA And CC) Or (BB And DD)
Are you checking for correct answers, or answers that were actually True or False?
If you are looking for correct answers, how is that information stored?
If you actually mean T/F questions that must have been answered True, then do
you at any time have to check for an answer being False?
Can the conditions be forward referencing (#8 condition depends on #12)
(That might happen if the questions are to be randomized)
These are only a few questions that I can think of right off. All the information
you know of or can offer, would serve to help in evaluating possible solutions.
LFS
| |
| Bob O`Bob 2004-03-30, 3:30 pm |
| =?Utf-8?B?RGFycmVuIFJoeW1lcg==?= wrote:
> It was originally:
>
> EventQuestion(23)=true OR EventQuestion(25)=true (which I would say makes
> understanding the problem easy - or as you say 'a format that is easy for
> humans to read')
>
> but I changed it as I was hoping this would make it easy for me to evaulate/calculate.
>
> e.g. Use the split function on it - then change the numbers to the answer
> of that question. Add the elements of the array into a string and evaluate
> the expression. Easy. Or so I thought.
>
> So what would your design be? Ive been through a few designs and they all
> seem v tricky when you start adding () and additional conditions.
Looks like you've created something akin to the infamous "come from"
programming statement.
Having worked on some university and lawschool examination programs, I could
tell you more than one way to do it, but there's probably no such thing as "best"
The main thing I'd recommend is move your logic to where the questions get
answered - don't wait until you get to question 27 to determine whether you
even want to ask that one or not. Back on "question 23" and again on q25 you
should have taken an action to enable the appropriate later question(s).
Storage of such info _might_ look something like this:
23:t27f-30
24:a61a-62b64
25:t27
Which you could read like this:
Question 23 - if answer "t" enable question 27, if answer "f" disable question 30
Question 24 - if answer "a" enable 61 and disable 62, if answer "b" enable 64
25 if answer "t" enable 27
There's unlimited possibile ways to do something like this, but first I'd recommend
forward-looking logic instead of backward.
And if you really *need* a format that is easy for humans to read (and write)
(we did, because our instructors and proctors were no programmers), then you
might consider writing a translation program, or as we did - an exam editor app.
Bob
--
|
|
|
|
|