[VB.NET] Tableau avec lignes variable

BobyCode Messages postés 9 Statut Membre -  
Kalissi Messages postés 221 Statut Membre -
Bonjour,

Je souhaiterais créer un tableau à 2 dimensions dont les colonnes sont définis mais pas les lignes.

Ex :
Dim tableau(i,4) as Object

i étant une variable qu'on ne connait pas et varie selon le résultat de la boucle ci-dessous
For col As Integer = iFirstColumn To iLastColumn
If oExcelRangeArray(i + j, col) IsNot Nothing Then
If oExcelRangeArray(i + j, col).ToString = sPresence Then
oTest(k, 0) = oExcelRangeArray(i, iColumnPostes)
oTest(k, 1) = sNomMachine
oTest(k, 2) = oExcelRangeArray(i + j, iColumnEquipe)
oTest(k, 3) = "" & oExcelRangeArray(iLigneJour, col) & " " & oExcelRangeArray(iLigneMois, col) & " 2014"
k += 1
End If
End If
Next


Merci de votre aide

1 réponse

  1. Kalissi Messages postés 221 Statut Membre 20
     
    Bonjour,

    Utiliser une liste fortement typé.

    En connaissant les colonnes, tu créé une classe que tu appele Entite.


    Public Class Entite

    #Region "--- Attributs ---"

    Private Shadows zCol1 As String = String.Empty
    Private Shadows zCol2 As String = String.Empty
    Private Shadows zCol3 As String = String.Empty
    ' etc...

    #End Region

    #Region "--- Propriétés ---"

    Public Property Col1() As String
    Get
    Return Me.zCol1
    End Get
    Set(ByVal value As String)
    Me.zCol1 = value
    End Set
    End Property

    Public Property Col2() As String
    Get
    Return Me.zCol2
    End Get
    Set(ByVal value As String)
    Me.zCol2 = value
    End Set
    End Property

    Public Property Col3() As String
    Get
    Return Me.zCol3
    End Get
    Set(ByVal value As String)
    Me.zCol3 = value
    End Set
    End Property

    ' Etc ...

    #End Region

    #Region "--- Constructeur ---"

    ''' <summary>
    ''' Constructeur par défaut
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub

    #End Region

    End Class


    Ensuite à partir d'une autre classe ou d'une "Form"
    tu utilises cette classe avec une liste fortement typé.


    Public Class Client

    #Region "--- Attributs ---"

    Private Shadows zEntiteLocal As Entite = Nothing
    Private Shadows zLsEntite As IList(Of Entite) = New List(Of Entite)

    #End Region

    #Region "--- Propriétés ---"

    Private Property EntiteLocal() As Entite
    Get
    Return Me.zEntiteLocal
    End Get
    Set(ByVal value As Entite)
    Me.zEntiteLocal = value
    End Set
    End Property

    Private Property LsEntite() As IList(Of Entite)
    Get
    Dim OldEnt As IList(Of Entite) = Me.zLsEntite
    If (OldEnt Is Nothing) Then
    Me.zLsEntite = New List(Of Entite)
    End If
    Return Me.zLsEntite
    End Get
    Set(ByVal value As IList(Of Entite))
    Me.zLsEntite = value
    End Set
    End Property

    #End Region

    #Region "--- Constructeur ---"

    ''' <summary>
    ''' Constructeur par défaut
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub

    #End Region

    #Region "--- Méthodes ---"

    Public Sub AjouterEntite()

    Dim Chaine As String = "10,20,30"

    LsEntite = LireEntite(Chaine)

    End Sub

    Public Function LireEntite(ByVal pVar1 As String) As IList(Of Entite)

    Dim LsLocal As IList(Of Entite) = New List(Of Entite)
    Dim Ent As Entite = Nothing
    Dim Chaine() As String = pVar1.Split(","c)

    Dim Limite As Int32 = Chaine.GetUpperBound(0)

    Ent = New Entite
    Ent.Col1 = Chaine(0)
    Ent.Col2 = Chaine(1)
    Ent.Col3 = Chaine(2)

    LsLocal.Add(Ent)

    Return LsLocal

    End Function

    #End Region

    End Class


    As-tu saisie l'astuce ?

    K
    0