views:

78

answers:

2

I'm working on some VB.net code that I inherited and am seeing some very strange behavior when trying to lookup a value in a Interop.Scripting.Dictionary object.

Here's the output from my watches. The expressions are in italics and the return values are bolded:

oAwayBalanceTeam.Dates("40068") 1 {Integer} Object

CStr(Int(oTempBooking.StartDateTime.ToOADate)) "40068" String

oAwayBalanceTeam.Dates(CStr(Int(oTempBooking.StartDateTime.ToOADate))) Nothing Object

Notice the first watch returns an integer with a value of 1 when a string literal key of "40068" is passed in. The second watch returns the string "40068". However, when passing the expression from the second watch as the key value in the 3rd watch Nothing is returned.

Anyone have any ideas what's going on here?

A: 

Can you provide a more complete repro here (and in particular what version of Visual Studio you are using). I tried the following code on Visual Studio 2008 RTM and got the expected result in every case.

Code

Module Module1

    Sub Main()
        Dim map = New Scripting.Dictionary
        map("40068") = 1
        Stop
    End Sub

End Module

Expressions Watched

  • map("40068") 1 {Integer} Object
  • CStr(Int("40068")) "40068" String
  • map(CStr(Int("40068"))) 1 {Integer} Object
JaredPar
Unfortunately I can't easily summarize. The code is really ugly. It's hundreds of lines to get the complete picture here and spans 3 or 4 code files. I copied the watches from the same break point though if that helps at all.I'm using:Microsoft Visual Studio 2008 Version 9.0.21022.8 RTMMicrosoft .NET Framework Version 3.5 SP1Microsoft Visual Basic 2008 91904-270-9795282-60037
Craig M
WHat is the type of oAwayBalanceTeam.Dates?
JaredPar
Interop.Scripting.Dictionary
Craig M
A: 

On a suggestion from a coworker, I tried assigning the expression from the second watch into a string and passing that var to the Dictionary.

Dim sKey As String

sKey = CStr(Int(oTempBooking.StartDateTime.ToOADate))

oAwayBalanceTeam.Dates(sKey)

This worked for some reason whereas the expression alone did not. While my problem is solved for now, I'd still love to know why this happened if anyone has an idea.

Craig M