Array Function

ultraman

Centurion
Joined
Dec 31, 1969
Messages
138
Location
Quebec, Canada
There's once again trouble in Dreamland !

In an ancien era where dinosaurs and VB6 ruled the world, there was an easy too use (yet very practical) function named "Array" that tranformed everything in (guess what ?) an Array !

Now, the evil Bill destroyed that function so that we have to waste our time finding new (more complicated) solutions.

Is there anyone outhere that would have found something that would work approximately like the Array function ?
 
I have no idea what the VB6 Array function was but here are 2 thoughts:
Array class to manipulate an array's data.
ArrayList to add and remove items easily.
 
Well... first of all, the Array() function was working like this :
Visual Basic:
Dim arrPara as Variant
arrPara = Array("12", "45", "HelloWold")

So there was no need for 3 lines of code (like with the .Add method of the ArrayList).

But finally, I used a ParamArray in my method definition and it works fine.

Visual Basic:
Public Sub SetColumnsHeaders(ByVal ParamArray pArray() As String)
        Dim i As Integer

        Try
            For i = LBound(pArray) To UBound(pArray) Step 2
                ts.GridColumnStyles(CInt(pArray(i))).HeaderText = pArray(i + 1).ToString
            Next
        Catch e As Exception
            MessageBox.Show(e.Message)
        End Try
    End Sub


'Call the sub
SetColumnsHeaders("0", "Number", "1", "Region", "2", "Members")
 
The Array() function in VB6 was rather ugly because it returned a variant array. There's an equally easy way in .NET which is not ugly at all:
Visual Basic:
Dim stringArray As String() = {"Item 1", "Item 2", "Item 3"}
Equiv in VB6 to
Visual Basic:
Dim stringArray() As String

stringArray = Array("Item 1", "Item 2", "Item 3")
 
Back
Top