Structure maStructure Public nom As String Public prenom As String End Structure Sub Principal() 'Créer une liste d'éléments maStructure Dim montableau As New List(Of maStructure) 'Ajouter des éléments à la liste Remplit_maStructure(montableau) For Each elt As maStructure In montableau Console.WriteLine(elt.nom) Next End Sub Sub Remplit_maStructure(ByRef tableau As List(Of maStructure)) ' Ajouter 3 élements au tableau maStructure Dim elt As maStructure For i As Integer = 0 To 2 elt.nom = "TestNom_" + i.ToString elt.prenom = "TestPrenom" tableau.Add(elt) Next End Sub
Dim montableau as mastruc
Sub Principal() dim retour as integer Dim montableau as mastruc ' un arraylist de ma structure ' APPEL MA FONCTION ET REMPLI MON ARRAY Rempli_mastructure montableau 'je ne connai pas le vb.net ou vb2005 donc vérifie la syntaxe avant d'essayer for i=0 to montableau.lengh writeln(montable(i).nom next i end sub Sub Rempli_mastruct(byval tableau as mastruct) 'byval me semble plus approprié ' Ajoute 2 élement au tableau mastructure for i=0 to 2 tableau(i).nom="Testnom"+i.tostring tableau(i).prenom="Testprenom" next End sub
Structure maStructure Public nom As String Public prenom As String End Structure Sub Principal() 'Créer une liste d'éléments maStructure Dim d() As maStructure ReDim d(2) 'tu redimensionnes selon que tu désires 'Ajouter des éléments à la liste Remplit_maStructure2(d) For i = 0 To d.Length - 1 Console.WriteLine(d(i).nom + " " + d(i).prenom) Next End Sub Sub Remplit_maStructure2(ByRef tableau() As maStructure) ' Ajouter 3 élements au tableau maStructure For i As Integer = 0 To 2 tableau(i).nom = "TestNom_" + i.ToString tableau(i).prenom = "TestPrenom_" + i.ToString Next End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDu coup je n'ai pas testé celle de NSuadi mais peut etre qu'elle fonctionne également.Sauf que je voulais éviter un tableau à cause du Redim qui n'est pas trés optimisant.