Extends is genial

Hello everyone I do not come to ask a question but to share with you my joy of having found a great feature: “Extends”

For example, I want to place entetes on a box list.
Before doing this:

listeBox.HeaderAt ( 01 ) = "AA"
listeBox.HeaderAt ( 02 ) = "BB" 
listeBox.HeaderAt ( 03 ) = "CC" 
listeBox.HeaderAt ( 04 ) = "DD"

and now :

listeBox.headers ( “AA,BB,CC,DD” )

Here is the headers method placed in a module:
Var col As Integer
Var headers() As String

headers = L_headers.ToArray ( "," )
col = 0
For Each h As String In headers
  If col <= ListBox.LastColumnIndex Then
         ListBox.HeaderAt ( col ) = h
  Else
         ListBox.HeaderAt ( col ) = ""
  End If
  col = col + 1
Next

Exception err
Break
End Sub

And then for a dictionnary

Function listeKeys(Extends dico As Dictionary) As string
' Permet d'obtenir une liste des key cle01,cle02... d un dictionnaire

For Each de As DictionaryEntry In dico
  If tx_keys = "" Then
    tx_keys = tx_keys + de.Key.StringValue
  Else
    tx_keys = tx_keys + " , " + de.Key.StringValue
  End If 
Next

Return tx_keys

`

var liste as string = Un_Dico. listeKeys

`

2 Likes

Yes, it’s a great language feature. By using the Extends modifier, you’re creating what is known as an “Extension Method”.

Because it appears you’re using a number of arguments with it, are you also using the ParamArray modifier to make the number of arguments dynamic? Also a great feature :blush:

this variable tx_keys seems outside of the method or you removed this line.

i agree this Extends is very useful.

FromArray is nice no make a csv list, unfortunately not for variant arrays.

Var d As New Dictionary("left" : 0, "top" : 10, "width" : 300, "height" : 300)

Var k() As String
For Each de As DictionaryEntry In d
  k.Add de.Key.StringValue
Next

System.DebugLog String.FromArray(k, ",")

Interestingly, to reference another thread, the French word “genial “ does not translate to the English word “genial “.

But, I knew what @J_Luc_Pellerin meant and I agree.

I mistake a ligne
var tx_keys as string

This method might also benefit from ParamArray:

Sub Headers (Extends List As DesktopListBox, ParamArray Columns() As String)

Then you do

List.Headers("AA", "BB", "CC", "DD")
5 Likes

Yes Thanck you for your reply