Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collection behavior when adding a new item
Message
From
24/07/2006 12:02:41
 
 
To
24/07/2006 11:35:34
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01138855
Message ID:
01139227
Views:
14
Hi,

I didn't say my example fixed anything - just made plainer what the problem was. In your example below, if there is no ReDim(), you are still adding two *references* to the same loCondition object to the oDropDownCondition collection so obviously loCondition is pointing to the same object in both iterations of ForEach and thus loCondition(1) will be identical in both cases...

Using Redim in your example creates a new loCondition object but the reference held in oDropDownCondition still points to the original instance.

Try this:
        Dim loCondition(2) As Object
        loCondition(1) = "One"
        loCondition(2) = "Two"
        Dim oRef As Object = loCondition
        ReDim loCondition(2)
        loCondition(1) = "Three"
        loCondition(2) = "Four"
oRef will show the original ("One","Two"), loCondition the new ("Three,Four")
HTH,
Viv


>>The loCondition in the ForEach is not the same as the loCondition object..
>>In the second case oDropDownCondition holds two references to the same object. Using :
>>
>>       For Each loX In oDropDownCondition
>>           oApp.AddJavascriptMessage(loX(1))
>>       Next
>>
>
>This is not a factor. If I do this, I end up in the same situation:
>
>
>        Dim loCondition(2) As Object
>        Dim loConditionResult(2) As Object
>
>        loCondition(1) = "NoDBUsers"
>        loCondition(2) = "NoEntity=" + oDashboard.nEntity.ToString
>        oDropDownCondition.Add(loCondition)
>        loCondition(1) = "NoDBUsers2"
>        loCondition(2) = "NoEntity=" + oDashboard.nEntity.ToString
>        oDropDownCondition.Add(loCondition)
>
>        For Each loConditionResult In oDropDownCondition
>            oApp.AddJavascriptMessage(loConditionResult(1))
>        Next
>
>
>The only way to have it ok is to have it like this:
>
>
>        Dim loCondition(2) As Object
>
>        loCondition(1) = "NoDBUsers"
>        loCondition(2) = "NoEntity=" + oDashboard.nEntity.ToString
>        oDropDownCondition.Add(loCondition)
>        ReDim loCondition(2)
>        loCondition(1) = "NoDBUsers2"
>        loCondition(2) = "NoEntity=" + oDashboard.nEntity.ToString
>        oDropDownCondition.Add(loCondition)
>
>        For Each loCondition In oDropDownCondition
>            oApp.AddJavascriptMessage(loCondition(1))
>        Next
>
>
>Note that I could have use loConditionResult for the For Each. It is not a factor in this situation. The only way to make it work is to ReDim loCondition everytime I need to add a new item. This is really weird.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform