CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    [RESOLVED] Visual Basic ate my variable!

    Can VB6 reassign a value just because it's of the same type? I used a member of a structure in a parameter that will return a structure of the same type as the one used in the parameter. Wait there's more: I used that return in the parameter in another method call (nested methods). My original structure used in the innermost nested method ends up equaling the returned value. To clarify I'm using an integer value of a member of the original structure and is passed by value not reference... Does vb6 not do nested methods?

    So below is a simplified illustrated example of how everything is set up:

    Code:
    '--- Returns a SomeStruct
    FunctionC(byVal i as integer) as SomeStruct
      .
      .
      .
    end Function
    
    FunctionA()
      dim A as SomeStruct
      .
      . 
      FunctionB( FunctionC(A.SomeInt) )
      .
      .
    end Function
    
    FunctionB( ByVal B as SomeStruct )
      .
      .
      .
    end Function
    Somehow during the call to FunctionB, "A" equals what is supposed to be "B" even after FunctionB returns.

    Sooo yeah... any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic ate my variable!

    Doesn't make sense. Include a sample.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    Re: Visual Basic ate my variable!

    Can't. Proprietary code. Plus it takes awhile to set up you're enviroment (dll's, third-party) so even if I send you the code you can't run it. I'm not allowed to publish even a small portion.

    I know it doesn't make sense. I've had my coworkers look at this and we've come to no conclusion. Googling vb6 and nested methods produced nothing.

    I'm more wondering if anyone else has had this happen to them.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Visual Basic ate my variable!

    You have not given enough to go on, no idea what B is returning nor what it is being assigned to.

    But to answer the part of the question that can be answered, Yes Vb does do nested methods just fine. I have used them numerous times over the years and whenever there was an issue it was always due to a mistake in the code.
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    Re: Visual Basic ate my variable!

    Ok... so it's not vb6 it's a really badly planned/executed DLL class that uses a static global class that has only one instance of the parent member. Using an accessor to retrieve a structure that is a member of the parent class then changes the parent class to point at the structure's parent. Basically if I'm currently pointing to A but I use an accessor to grab a member of B turns A into B.

    I know vb6 does nested queries I was wondering if there was an unpublished limitation to its processing/interpretation/execution of nested methods. In this case yes it was the code but I have seen vb6-ism/quirks to defy basic logic (no pun intended). I was hoping this was vb6 because I could use that as another point to let us update this project. If it's our code they'll just say fix it...

    Thanks for you for your time everyone...

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic ate my variable!

    Code:
    changes the parent class to point
    That would be a pointer, which VB6 does NOT have
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    Re: Visual Basic ate my variable!

    Quote Originally Posted by dglienna View Post
    That would be a pointer, which VB6 does NOT have
    A pointer is not exactly what I'm talking about. I used "point" to mean "reference", or "equals". I can only instantiate one instance of the DLL class. Whenever I query for another structure when I already have one changes all variables of the DLL class to the one I just queried for. Basically I'm only allowed to have/use the one I queried for.

    It's not a pointer issue (meaning I tried to use pointers in VB6). This is just a badly designed global class that exists for the life of the application. The parent structure exists independent of any new'ed variable of the class's type or it's children class. The parent controls the children. If I query for another saved structure or one of it's many members (meaning I use an accessor to retrieve a member of a different structure), every variable of that DLL class (parent or child) in existence is then changed and they all "point" to the parent that I queried for.

  8. #8
    Join Date
    Jan 2002
    Posts
    195

    Re: Visual Basic ate my variable!

    Sounds to me like the problem is in the coding of the DLL. I'd look there. Perhaps something is being passed ByRef when it should be passed ByVal. I exsperanced a similar problem a long time ago when I used VB6 for me it turned out to be a conflect in varibale names. I had a local and a global variable with the same name. I'd attempt to make a change to a local variable and it would change the global instead.

  9. #9
    Join Date
    Apr 2006
    Location
    Rhode Island
    Posts
    32

    Re: Visual Basic ate my variable!

    Well sort of... apparently the class is set up to only allow one instance of nay object of that class to exist at any one time during the life of the application. Basically when querying for a member the parent queries for EVERYTHING. So the accessor actually refreshes the entire object and every instance of that same class... it's terrible... It's a custom DLL we made (actually someone who doesn't and hasn't for quite awhile works here anymore) is doing this...

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Visual Basic ate my variable!

    Hence, the POINTER...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured