Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ?

Now go on, boy, and pay attention. Because if you do, someday, you may achieve something that we Simpsons have dreamed about for generations: You may outsmart someone!

--Homer Simpson

Posted

Well... first of all, the Array() function was working like this :

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.

 

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")

Now go on, boy, and pay attention. Because if you do, someday, you may achieve something that we Simpsons have dreamed about for generations: You may outsmart someone!

--Homer Simpson

  • *Experts*
Posted
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:
Dim stringArray As String() = {"Item 1", "Item 2", "Item 3"}

Equiv in VB6 to

Dim stringArray() As String

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...