[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1212
  • Last Modified:

VB6 and the equals sign

This really has me puzzled.  I'm debugging in a VB6 app.  In the following line:

                    M7Tag = Seed1Children("MovieID")

 the value for M7Tag is 115 while the value of Seed1Children("MovieID") is 391 !!!
How can that be?  I thought one of the immutible laws of computing was 'What's on the left of an equal sign must be the same as what's on the right.'

M7Tag is a global variable.  Seed1Chidren("MovieID") is a field in a Rescordset.  I get no error message.  I put a breakpoint 10 lines or so below this line - and got this result.  Does anyone know how VB6 could parse this line and not complain (Type Mismatch, Variable not defined, etc.)?  I don't know how to debug if I can't see what's happened here.  If you can't believe in an = sign, what's left in Life?    Signed,

Waiting for the sky to fall in Chicago

0
wjshore
Asked:
wjshore
3 Solutions
 
JimBrandleyCommented:
"Waiting for the sky to fall in Chicago" - I suspect the the clue may be here:
"M7Tag is a global variable"
Is it possible something else is writing to that variable after you do it in this code?

I would set a breakpoint before the assignment, and add M7Tag to the watch window. Then step over each line of succeeding code and see when it does (or does not) change.

Jim
0
 
Patrick MatthewsCommented:
Hello wjshore,

>>I thought one of the immutible laws of computing was 'What's on the left of an equal sign must
>>be the same as what's on the right.'

In a word, no.  Depends on the context.

The line you show above looks to me like an example of = as a scalar variable assignment
operator:

[Let] M7Tag = Seed1Children("MovieID")

I put the Let in brackets because in VB and VBA, it's optional.

On the other hand, in logical expressions, = is a logical operator:

If VarX = VarY Then

The logical operator returns True or False.

If you post the whole code and give some more context behind your question perhaps I can be of
more assistance.

Regards,

Patrick
0
 
PaulHewsCommented:
Normally it should work, but VB has a few stealthy issues that you need to watch for.

Go to Debug menu, Add Watch and add M7Tag.  Check the "Break when Value Changes" option.  Use "All Procedures"  "All Modules", as this is a global.  Now when the value of M7Tag is changed, your program will break at the code line where it happened (and you will know it doesn't happen somewhere else.)

How is M7Tag declared?  Double check that you have not declared it locally as well as globally.  (If you do this, VB will not complain, but will use the local declaration when it is in scope.)

Is Option Explicit at the top of your form/module/class?  If not, put it in and re-run.


0
 
wjshoreAuthor Commented:
I'm following advice and most of the puzzle remains.  I added a second, earlier, breakpoint and M7Tag watch.  Sure enough, when I stepped thru with F8, the value changed and M7Tag matched Seed1Children("MovieID").  This still leaves me the question; Why did it require stepping thru?  When I set the later breakpoint, didn't VB execute all the code up to that?  I thought that was the purpose of breakpoints?  p.s. Option Explicit is there.
0
 
PaulHewsCommented:
If there's nothing in the procedure that could have changed the variable, the only possibility is that something outside the procedure changed it.  

Because VB is event driven, code can branch to other events, pushing an executing procedure on the stack until the event code is done.  If you are using DoEvents in the executing code, it will typically allow this type of branching away.  (Not saying that's necessarily what happened, but one possibility I can think of.)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now