
03-31-2020, 01:55 PM
|
 |
Expert
|
|
Join Date: May 2013
Location: USA
Posts: 700
|
|
VBA is conflatng vx and ox!
Ok, this is weird. I'm writing a VBA program, and part of it looks like this:
Code:
Set StdXcts = New Collection
For Each oxct In oTSS.Xcts
bs = (InStr(oxct.Handles, vh) > 0)
oxct.bStd = bs
If bs Then
vx = oxct.Name
Set ox = New Obj2
StdXcts.Add ox, vx
ox.Name = vx
End If
Next oxct
Note the part in the middle where I tell it that vx is to become a value (a string), and immediately afterward I set ox to be a new object. Here's the weird thing: As soon as I execute "vx=oxct.Name", both vb and ox become the string ("ARSB"). Then at the next statement, "Set ox=New Obj2", both vx and ox become a new object. Consequently when I try to add ox to the collection using a key of vx, the statement fails.
I stopped the debugger and tried again. I closed the workbook, reopened it and tried again. I closed Excel, then restarted it and tried again. I disconnected from the client machine, reconnected, restarted Excel and tried again. Finally I disconnected, rebooted my own PC and tried again. It's still doing it. So I conclude it's not some temporary difficulty; either it's a bug in the latest version of Excel or my workbook is corrupted.
But before I start trying anything extreme, can anyone imagine any other explanation? Is there anything I could possibly have done earlier in the program that accidentally created an equivalence between vx and ox, for instance?
...Oh, forgot to mention: I tried changing one of the variable names (from ox to oo) and it works!
Last edited by BobBridges; 03-31-2020 at 02:12 PM.
Reason: Forgot to say...
|