|
| Author |
Message |
Randy Gardner
Joined: 04 Oct 2007 Posts: 53
|
Posted: Sat Feb 23, 2008 4:39 pm Post subject: How do I write this IF THEN ELSE logic |
|
|
How do I write this statement?
If :
VarName1 is true
VarName2 is True
Then:
Call Sub1
Call Sub2
If:
VarName3 = "NotString1"
Else:
Call Sub4
If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
Varname3 = "String1" Then Call Sub3 Else Call Sub4
Evrything I try is good up to the ELSE option.
--
Thank you,
Randy
Archived from group: microsoft>public>vb>general>discussion |
|
| Back to top |
|
 |
G S
Joined: 23 Feb 2008 Posts: 2
|
Posted: Sun Feb 24, 2008 2:02 am Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Which 'If' is the 'Else' to?
I guess it is the 'End If' that is the problem.
"Randy Gardner" skrev i meddelandet @microsoft.com...
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
> --
> Thank you,
>
> Randy |
|
| Back to top |
|
 |
dpb
Joined: 04 Oct 2007 Posts: 568
|
Posted: Sat Feb 23, 2008 7:03 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Randy Gardner wrote:
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
I have no idea what the logic is intended to be but assuming VN1 and VN2
must be True then something like
If VN1 And VN2 Then
Sub1
Sub2
End If
If VN3 = "S1" Then
Sub3
Else
Sub4
End If
That, of course, assumes the two cases are independent--if the test for
VN3 is only intended to be true for the case when VN1 and -2 are True,
then that If...Else...EndIf needs to be moved inside the previous.
You need a well-formed truth table to decipher what is supposed to
happen when, then implement that rather than just throwing stuff around
willy-nilly and see what happens...
-- |
|
| Back to top |
|
 |
Galen Somerville
Joined: 04 Oct 2007 Posts: 55
|
Posted: Sat Feb 23, 2008 5:10 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
"Randy Gardner" wrote in message @microsoft.com...
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
> --
> Thank you,
>
> Randy
If VarName1 then
if VarName2 then
Call Sub1
Call Sub2
Endif
ElseIf VarName3 = "String1" then
Call Sub3
Else
Call Sub4
Endif
Or thereabout
Galen |
|
| Back to top |
|
 |
christery
Joined: 11 Jan 2008 Posts: 71
|
Posted: Sat Feb 23, 2008 7:32 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
On 23 Feb, 20:39, Randy Gardner
wrote:
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
> --
> Thank you,
>
> Randy
there is a ':' that is a lot like a label, or am I thinking wrong...
so u created labels if: then: and else:, but it (the compiler) should
have complaind about that 2Nd if...
So the end if is not the initial prblem, but it will be when the :
leaves as G S suggested
//CY |
|
| Back to top |
|
 |
argusy
Joined: 04 Oct 2007 Posts: 145
|
Posted: Sun Feb 24, 2008 2:16 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Randy Gardner wrote:
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
you'd save everybody a lot of grief trying to work out what you want, if you
just INDENTed your algorithm.
ie is your statement
IF
vn1 is true and (???) vn2 is true then
call sub1
call sub2
if vn3 = "notstring1" (THEN) ???
endif (???)
else
call sub4
endif (???)
endif (???)
There's a heap of variations to your algorithm (some already pointed out), but
we'll get nowhere (or go 'round in circles) until you clear up just what your
intentions are (especially if you drop in those 'end if' thingies)
If you do that, you may find out exactly what you're trying to do, and needn't
have posted this in the first place.
Argusy |
|
| Back to top |
|
 |
argusy
Joined: 04 Oct 2007 Posts: 145
|
Posted: Sun Feb 24, 2008 2:44 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Randy Gardner wrote:
> How do I write this statement?
>
> If :
> VarName1 is true
> VarName2 is True
> Then:
> Call Sub1
> Call Sub2
> If:
> VarName3 = "NotString1"
> Else:
> Call Sub4
>
> If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> Varname3 = "String1" Then Call Sub3 Else Call Sub4
>
> Evrything I try is good up to the ELSE option.
Two more things
One:
You don't seem to understand the IF structure
It's not
IF.. THEN.. ELSE..
it's
IF.. THEN.. ELSE.. ENDIF
Two:
If you're developing a program, DO NOT TRY TO MAKE ONE-LINERS for "IF..."
structures. You can do that later, once you've worked out your (correct)
algorithm, but then if you don't document it properly, you may be saying
"huh!! what was I trying to achieve" years later (months, weeks, days even)
SEPARATE YOUR STRUCTURE WHILE YOU'RE DEVELOPING.
You nearly have it right in your algorithm (toss in a few 'ENDIF's here and
there to clarify), but stuffed it trying to write a one liner
Leave that to the professionals (Google Rick Rothstein's amazing record of
one-liners for examples, but be prepared for some doozies)
Argusy (again) |
|
| Back to top |
|
 |
christery
Joined: 11 Jan 2008 Posts: 71
|
Posted: Sun Feb 24, 2008 3:56 am Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
On 24 Feb, 00:14, argusy wrote:
> Randy Gardner wrote
> SEPARATE YOUR STRUCTURE WHILE YOU'RE DEVELOPING.
and be aware of the dangling else problem... *smile*
//CY |
|
| Back to top |
|
 |
Randy Gardner
Joined: 04 Oct 2007 Posts: 53
|
Posted: Sun Feb 24, 2008 4:32 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
I didn't clarify that all must be a single statement evaluation.
It follows all the If - Then execution except in the final evaluation it is
IF - Then - Else. My experience is it will never do the Else the way I wrote
it.
Is your response a single statement?
Thanks.
--
Thank you,
Randy
"Galen Somerville" wrote:
>
> "Randy Gardner" wrote in message
> @microsoft.com...
> > How do I write this statement?
> >
> > If :
> > VarName1 is true
> > VarName2 is True
> > Then:
> > Call Sub1
> > Call Sub2
> > If:
> > VarName3 = "NotString1"
> > Else:
> > Call Sub4
> >
> > If VarName1 = True Then If VarName2 = 1 Then Call Sub1: Call Sub2: If
> > Varname3 = "String1" Then Call Sub3 Else Call Sub4
> >
> > Evrything I try is good up to the ELSE option.
> > --
> > Thank you,
> >
> > Randy
>
> If VarName1 then
> if VarName2 then
> Call Sub1
> Call Sub2
> Endif
> ElseIf VarName3 = "String1" then
> Call Sub3
> Else
> Call Sub4
> Endif
>
> Or thereabout
>
> Galen
>
>
> |
|
| Back to top |
|
 |
"Rick Rothstein \
Joined: 04 Feb 2008 Posts: 37
|
Posted: Sun Feb 24, 2008 8:02 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
>I didn't clarify that all must be a single statement evaluation.
Why on earth would single line If-Then-Else statements EVER be a
requirement? Personally, I think such a requirement is, well, insane... and
you can see the reason why based on the fact that you had to come here for
help.
Rick |
|
| Back to top |
|
 |
dpb
Joined: 04 Oct 2007 Posts: 568
|
Posted: Sun Feb 24, 2008 7:03 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Randy Gardner wrote:
> I didn't clarify that all must be a single statement evaluation.
You also didn't clarify the logic tree so anybody could possibly infer
what is correct operation.
> It follows all the If - Then execution except in the final evaluation it is
> IF - Then - Else. My experience is it will never do the Else the way I wrote
> it.
That happens w/ incorrect syntax.
> Is your response a single statement?
I'd _NEVER_ consider that as a defining consideration.
Do you want correct code or one line of code that may (or may not) do
the right thing?
-- |
|
| Back to top |
|
 |
Randy Gardner
Joined: 04 Oct 2007 Posts: 53
|
Posted: Sun Feb 24, 2008 5:14 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Not very helpful and not very friendly. Just an opinion!
Please avoid responding to my Postings!!!!
--
Thank you,
Randy
"Rick Rothstein (MVP - VB)" wrote:
> >I didn't clarify that all must be a single statement evaluation.
>
> Why on earth would single line If-Then-Else statements EVER be a
> requirement? Personally, I think such a requirement is, well, insane... and
> you can see the reason why based on the fact that you had to come here for
> help.
>
> Rick
>
> |
|
| Back to top |
|
 |
"Rick Rothstein \
Joined: 04 Feb 2008 Posts: 37
|
Posted: Sun Feb 24, 2008 8:23 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
>> >I didn't clarify that all must be a single statement evaluation.
>>
>> Why on earth would single line If-Then-Else statements EVER be a
>> requirement? Personally, I think such a requirement is, well, insane...
>> and
>> you can see the reason why based on the fact that you had to come here
>> for
>> help.
>
> Not very helpful and not very friendly. Just an opinion!
>
> Please avoid responding to my Postings!!!!
No problem... your wish is my command.
Rick |
|
| Back to top |
|
 |
Steve Gerrard
Joined: 04 Oct 2007 Posts: 1164
|
Posted: Sun Feb 24, 2008 6:06 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
Randy Gardner wrote:
>
> Please avoid responding to my Postings!!!!
>
A simpler method for acheiving the goal of having no one respond to your posts
would be to not make them in the first place. However, behaving like an idiot
will probably also accomplish that goal...
By the way, you can fix your original single statement version by putting an
Else in front of the second If. Oh wait, you don't want any responses... |
|
| Back to top |
|
 |
Ralph
Joined: 04 Oct 2007 Posts: 4148
|
Posted: Sun Feb 24, 2008 8:12 pm Post subject: Re: How do I write this IF THEN ELSE logic |
|
|
"Randy Gardner" wrote in message@microsoft.com...
> Not very helpful and not very friendly. Just an opinion!
>
> Please avoid responding to my Postings!!!!
>
> --
> Thank you,
>
> Randy
>
LOL!
You are a silly person and your reply is straight out of "Hitchhiker Guide",
as you managed to blow off the one person around here that is likely to
provide you with a reasonable solution.
Instead of being aloof and annoying you should have just answered a few
questions. Instead you are going to get equally silly answers like this one
....
[Watch for word wrap]
If Not VarName1 Then If VarName3 = "String1" Then Sub3 Else Sub4 Else If
VarName2 Then Sub1: Sub2
enjoy
-ralph
|
|
| Back to top |
|
 |
|