0

I have an array which originally was a Variant array in VB6.

Example code in VB6:

ListBoxDrawings.List(X1, Y1) = myArray(X2, Y2)
myArray(A, B) = ListBoxDrawings.List(I, C)

After running it through ArtinSoft's VBUC, its values are handled using GetValue & SetValue.

Example code in VB.NET: (ignore conversion to ListView)

ListViewDrawings.Items(X1).SubItems(Y1).Text = CStr(myArray.GetValue(X2, Y2))
myArray.SetValue(ListViewDrawings.Items(I).SubItems(C).Text, A, B)

Since VB.NET doesn't do Variants, I figured out that the array should be typed as a 2D String Array. It seems like there's no reason to use GetValue/SetValue, as the former returns an Object and the latter takes one. This means that I'd have to cast the returned object as a String (Cstr) if I wanted to assign it to a variable, which seems like a pointless extra step that might introduce errors. Also, since the method has lots of overloads, the code might not be as clear. Is there any advantage to using SetValue / GetValue, or should I just consider that an artifact of VBUC converting a Variant, and access the array directly like the original code did?

VB.NET without Get/Set methods:

ListViewDrawings.Items(X1).SubItems(Y1).Text = myArray(X2, Y2)
myArray(A, B) = ListViewDrawings.Items(I).SubItems(C).Text
Wingman4l7
  • 649
  • 1
  • 8
  • 23

1 Answers1

1

Ditch the Object in favor of String for sure. Conversion tools almost always treat Variants as Object because in VB6 a Variant is the universal type, just as in .NET Object is.

tcarvin
  • 10,715
  • 3
  • 31
  • 52
  • So I shouldn't bother with the GetValue/SetValue methods, then? – Wingman4l7 Jun 04 '12 at 01:51
  • 1
    There is no advantage to GetValue / SetValue and plenty of disadvantages as you pointed out, so use your strongly-typed String array instead. – tcarvin Jun 04 '12 at 10:08