VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

If..Then..Else returns a false True

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
305 Views, 4 Replies

If..Then..Else returns a false True

I have not run into this before and I've banged my head on my desk enough
today so I must ask the vba guru's out there: "How can this happen?"
I can step through my macro and it all works as intended EXCEPT for the
following portion of code tha fails at the same place everytime....well, it
doesn't fail but it does enter an If function as if it evaluated to true
when I KNOW that it is not true, since the conditions have not been met, as
shown in the Locals window.

tan, entNext and ent are both set and valid, arc is dimmed but not set

at this point in the code it correctly evaluates 1* as false, goes to 2*
which correctly evaluates true, goes to 3* and this incorrectly evaluates as
true, even though the first test is should be false since ent.type evaluates
to kTangent and then the second test should fail anyway since arc has not
yet been set. By all rights, it should get all the way to 4* before the If
evaluates to True.
Any ideas as to why this happens?

1* If entNext.Type = kCurve And entNext.CCWFlag = True Then
If ent.Type = kCurve And arc.CCWFlag = True Then
aData(X - 1, 1) = "PCC"
ElseIf ent.Type = kCurve And arc.CCWFlag = False Then
aData(X - 1, 1) = "PRC"
End If
2* ElseIf entNext.Type = kCurve And entNext.CCWFlag = False Then
3* If ent.Type = kCurve And arc.CCWFlag = True Then
aData(X - 1, 1) = "PRC"
ElseIf ent.Type = kCurve And arc.CCWFlag = False Then
aData(X - 1, 1) = "PCC"
End If
4* ElseIf entNext.Type = kCurve And ent.Type = kTangent Then
aData(X - 1, 1) = "PC"
ElseIf entNext.Type = kTangent Then
If ent.Type = kCurve Then
aData(X - 1, 1) = "PT"
ElseIf ent.Type = kTangent Then
aData(X - 1, 1) = "PI"
End If
End If


--
Jeff Mishler
remove USES from email address to reply
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Jeff Mishler wrote:
> I have not run into this before and I've banged my head on my desk
> enough today so I must ask the vba guru's out there: "How can this
> happen?"

That's a serious mess of spaghetti you have there. Your code would be a
lot easier to maintain and read if you used a Select Case instead.

I also urge you to abandon all those compound tests. Unlike other
languages, all tests will be evaluated from left to right regardless of
the number of tests that fail prior to the last one. This makes tracking
bugs difficult at best.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Message 3 of 5
Anonymous
in reply to: Anonymous

I don't know about the kCurve vs kTangent test giving false positive, but it
looks like arc is a class?
with a property .CCWFlag ?
if that's the case, since it's dimmed, I believe the first reference to it
creates an instance(virtually setting it) and if the default value for the
.CCWFlag is = True then it would evaluate to True even though you didn't
specifically set it to a value.

not seeing any code it's just guessing in the dark
and not being a guru, it's really WILD guessing!
:-)~
the other thought is have you looked at Select case?
multiple levels of if statements are notoriously problematic it seems

I know none of that answers your questions but it gets pretty quiet around
here on the weekends sometimes so maybe something is better than nothing?
good luck
and go easy on that forehead
Mark

"Jeff Mishler" wrote in message
news:7C4C4694C137C5ABF703859955E1962F@in.WebX.maYIadrTaRb...
> I have not run into this before and I've banged my head on my desk enough
> today so I must ask the vba guru's out there: "How can this happen?"
Message 4 of 5
Anonymous
in reply to: Anonymous

Mark & Frank,
Thanks for responding. As it turns out, after I posted my question I decided
to try what both of you suggested. Using Select Case made it work and looks
alot better. 😉

I had originally thought the the If-Then-Else's would be just a couple quick
tests, but they quickly grew out of control as you saw.

As you can tell from my "spaghetti", I'm a real HACK at this VBA stuff and
all suggestions and contructive criticisms are welcome.

BTW, Mark, the arc is just a dimmed AeccAlignmentEntity and the .CCWFlag is
a property that only exists if that entity is of the type kCurve.

Thanks again,
Jeff

"Mark Propst" wrote in message
news:26A0559A62BDC475774DA6B0921EBB9E@in.WebX.maYIadrTaRb...
> I don't know about the kCurve vs kTangent test giving false positive, but
it
> looks like arc is a class?
> with a property .CCWFlag ?
> if that's the case, since it's dimmed, I believe the first reference to it
> creates an instance(virtually setting it) and if the default value for the
> .CCWFlag is = True then it would evaluate to True even though you didn't
> specifically set it to a value.
>
> not seeing any code it's just guessing in the dark
> and not being a guru, it's really WILD guessing!
> :-)~
> the other thought is have you looked at Select case?
> multiple levels of if statements are notoriously problematic it seems
>
> I know none of that answers your questions but it gets pretty quiet around
> here on the weekends sometimes so maybe something is better than nothing?
> good luck
> and go easy on that forehead
> Mark
>
> "Jeff Mishler" wrote in message
> news:7C4C4694C137C5ABF703859955E1962F@in.WebX.maYIadrTaRb...
> > I have not run into this before and I've banged my head on my desk
enough
> > today so I must ask the vba guru's out there: "How can this happen?"
>
>
Message 5 of 5
Anonymous
in reply to: Anonymous

like I said *WILD* guess!
:-)~
glad ya got it working

"Jeff Mishler" wrote in message
news:DB55E7C0A8C2194AA0AC9FB59CC73B80@in.WebX.maYIadrTaRb...

> BTW, Mark, the arc is just a dimmed AeccAlignmentEntity and the .CCWFlag
is
> a property that only exists if that entity is of the type kCurve.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report