manipuler une variable arraylist dynamiquement
Bonjour,
J'ai créé une classe contenant pleins de variables du type arraylist.
Pour chacune, j'ai créé une procédure qui permet de rechercher une valeur à l'intérieur, à partir d'une chaine
fournie en paramètre d'entrée.
Par exemple, j'ai une vingtaines de tableaux avec pour chacun d'eux ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
Private arCapacites As New ArrayList
Private intNbCapaciteInArray As Integer = 0
Public Sub New()
LoadCapacités()
End Sub
Private Sub AddCapacite(ByVal paramname As String, ByVal paramvalue As Object)
Dim tParams As String() = {paramname, paramvalue}
arCapacites.Add(tParams)
End Sub
Private Sub LoadCapacités()
AddCapacite("54501245", "16 personnes")
AddCapacite("98545416", "52 personnes")
AddCapacite("12000454", "28 personne")
... etc ...
End Sub
Public Function GetCapaciteType(ByVal strCodeTourinFrance As String) As String
Dim OutPut As String = ""
Dim MaxItem As Integer = intNbCapaciteInArray - 1
Try
For i As Integer = 0 To MaxItem
If strCodeTourinFrance = arCapacites(i)(0) Then
OutPut = arCapacites(i)(1)
i = MaxItem + 1
End If
Next
If OutPut = "" And BoolActiverOutputNotFound = True Then
OutPut = "<span style='color:#FF0000;'>" & Trim(strCodeTourinFrance) & "<span>"
End If
Catch ex As Exception
OutPut = "<span style='color:#FF0000;'>" & ex.ToString() & "<span>"
End Try
Return OutPut
End Function
Public Function GetReverseCapaciteType(ByVal strTexte As String) As String
Dim OutPut As String = ""
Dim MaxItem As Integer = intNbCapaciteInArray - 1
Try
For i As Integer = 0 To MaxItem
If InStr(arCapacites(i)(1), strTexte) > 0 Then
OutPut = arCapacites(i)(0)
i = MaxItem + 1
End If
Next
If OutPut = "" And BoolActiverOutputNotFound = True Then
OutPut = "<span style='color:#FF0000;'>--<span>"
End If
Catch ex As Exception
OutPut = "<span style='color:#FF0000;'>" & ex.ToString() & "<span>"
End Try
Return OutPut
End Function
Public Function WriteCapaciteType() As String
Dim strContenu As String = ""
Dim nbItems As Integer = intNbCapaciteInArray - 1
Try
For i As Integer = 0 To nbItems
strContenu = strContenu & "Ligne " & i & " => (" & arCapacites(i)(0) & ")(" & arCapacites(i)(1) &
")<br>"
Next
If strContenu = "" Then
strContenu = "<span style='color:#FF0000;'>Vide.<span>"
End If
Catch ex As Exception
strContenu = "<span style='color:#FF0000;'>" & ex.ToString() & "<span>"
End Try
Return strContenu
End Function |
Pour gagner du temps et alléger mon code, est-il possible d'attraper dynamiquement le nom d'un de ces objets
arraylist et de réécrire mes fonction de recherche en appelant le nom de la variable arraylist dynamiquement ?
C'est à dire, j'aimerai faire ceci :
Code:
1 2 3 4 5
|
Public Function Recherche(ByVal strTexte As String) As String
Dim arMyDynamicList As ArrayList = FindMaVariableByName(strTexte)
arMyDynamicList.Contains ......
End Function |
Est-ce possible et comment faire ?