VB6 and the equals sign

Posted on 2007-10-16
Last Modified: 2008-05-19
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

Question by:wjshore
    LVL 22

    Assisted Solution

    "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.

    LVL 92

    Assisted Solution

    by:Patrick Matthews
    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

    [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.


    LVL 38

    Expert Comment

    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.


    Author Comment

    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.
    LVL 38

    Accepted Solution

    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.)

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Using YubiKey with REST API application 2 54
    countAbc challenge 9 35
    strDist challenge 35 70
    Saving history changes to sub form 4 17
    This article will show, step by step, how to integrate R code into a R Sweave document
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now