msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I write this IF THEN ELSE logic
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions
Author Message
Randy Gardner



Joined: 04 Oct 2007
Posts: 53

PostPosted: Sat Feb 23, 2008 4:39 pm    Post subject: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
G S



Joined: 23 Feb 2008
Posts: 2

PostPosted: Sun Feb 24, 2008 2:02 am    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
dpb



Joined: 04 Oct 2007
Posts: 568

PostPosted: Sat Feb 23, 2008 7:03 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
Galen Somerville



Joined: 04 Oct 2007
Posts: 55

PostPosted: Sat Feb 23, 2008 5:10 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

"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
View user's profile Send private message
christery



Joined: 11 Jan 2008
Posts: 71

PostPosted: Sat Feb 23, 2008 7:32 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
argusy



Joined: 04 Oct 2007
Posts: 145

PostPosted: Sun Feb 24, 2008 2:16 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
argusy



Joined: 04 Oct 2007
Posts: 145

PostPosted: Sun Feb 24, 2008 2:44 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
christery



Joined: 11 Jan 2008
Posts: 71

PostPosted: Sun Feb 24, 2008 3:56 am    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
Randy Gardner



Joined: 04 Oct 2007
Posts: 53

PostPosted: Sun Feb 24, 2008 4:32 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
"Rick Rothstein \



Joined: 04 Feb 2008
Posts: 37

PostPosted: Sun Feb 24, 2008 8:02 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

>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
View user's profile Send private message
dpb



Joined: 04 Oct 2007
Posts: 568

PostPosted: Sun Feb 24, 2008 7:03 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
Randy Gardner



Joined: 04 Oct 2007
Posts: 53

PostPosted: Sun Feb 24, 2008 5:14 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
"Rick Rothstein \



Joined: 04 Feb 2008
Posts: 37

PostPosted: Sun Feb 24, 2008 8:23 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

>> >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
View user's profile Send private message
Steve Gerrard



Joined: 04 Oct 2007
Posts: 1164

PostPosted: Sun Feb 24, 2008 6:06 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

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
View user's profile Send private message
Ralph



Joined: 04 Oct 2007
Posts: 4148

PostPosted: Sun Feb 24, 2008 8:12 pm    Post subject: Re: How do I write this IF THEN ELSE logic Reply with quote

"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
View user's profile Send private message
Display posts from previous:   
Related Topics:
Boolean logic question I have 4 values A1, A2, B1, B2 and this If statement: if (A1 >= B1 and A1 <= B2) or (A1 <= B1 and A2 >= B1) then DoSomething I know that it simplifies to this if (A1 <= B2 and A2 >= B1) then DoSomething but why? My boolean maths is a little rusty. If it's

Tag cloud logic wanted I am working on a tag cloud which is based on the title node taken from a Yahoo RSS feed. Here's my tag cloud as it looks now. So far this is pretty trivial - I do a quicksort on the words, filter out all the small words I

Simple Or logic optimization Ok, this should be simple, but I'm just not finding a good solution. It's a simple If/Then using a single Or. Below you see that if either of these are true, then run code to update a file. If CRCStr <> FileCRCStr Or FileExists = False Then 'Code goes he

Looking for some logic help with dates and working outs. Dear All, I'm looking for a solution to this problem... I have some variables that hold date and time Public E_Day(1 To 5000) Public E_Month(1 To 5000) Public E_Year(1 To 5000) Public E_Hour(1 To 5000) Public E_Min(1 To 5000) Basically I'm

VB6, IF statement logic and function return values The problem that I am seeing is that some of my code is not running correctly. I'll try to explain. I have 3 IF statements, the second IF statement evaluates the return value of a function. For some reason the function always returns False, even though wh
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group