Probleme de recherche collection arraylist

Fermé
twix2010 Messages postés 13 Date d'inscription mercredi 23 mars 2011 Statut Membre Dernière intervention 21 décembre 2011 - 30 mars 2011 à 12:17
 Lupin - 30 mars 2011 à 14:59
Bonjour,



Module Module1
Dim list As New ArrayList

Sub ajouter()
Dim o1 As article = New article
Console.Write("entrer l article :")
o1.art = Console.ReadLine
Console.Write("entrer l pu:")
o1.pu = Console.ReadLine
Console.Write("entrer l qté:")
o1.qté = Console.ReadLine
list.Add(o1)
End Sub
Public Sub afficher()
Dim i As Integer = 0
While i < list.Count
Console.Out.WriteLine(CType(list.Item(i), article).identite)
i = i + 1
End While
End Sub
Public Sub supprimer()
Dim m As Integer
Console.Write(" entrer la position a supprimer : ")
m = Console.ReadLine
list.RemoveAt(m)
Dim i As Integer = 0
While i < list.Count
Console.Out.WriteLine(CType(list.Item(i), article).identite)
i = i + 1
End While
End Sub

Public Sub recherche()

Dim i As Integer = 0
Dim m As String
Dim trouve As Boolean = False
Console.Write("entrez l'article a rechercher :")
m = Console.ReadLine
While i < list.Count - 1 And trouve = False
If (CType(list.Item(i), article).art) = m Then
trouve = True
Console.Out.WriteLine(list(i).identite)
End If
End While
If trouve = False Then
Console.WriteLine("existe pa")
End If

End Sub


Sub Main()
Dim choix As Integer
Console.WriteLine("==========MeNu==========")
Console.WriteLine()
Console.WriteLine(" I ajouter")
Console.WriteLine(" II affichage ")
Console.WriteLine(" III supprimer ")
Console.WriteLine(" IV recherche ")
Console.WriteLine()
Console.WriteLine("========================")
Do

Console.WriteLine()
Console.Write("entrer votre choix : ")
choix = Console.ReadLine
Console.WriteLine()
Select Case (choix)
Case 1
ajouter()

Case 2
afficher()
Case 3
supprimer()
Case 4
recherche()
End Select
Loop While (choix <> 5)



End Sub

End Module







Public Class article
Private _art As String
Private _pu As Double
Private _qté As Integer
Public Property art() As String
Get
Return Me._art
End Get
Set(ByVal value As String)
Me._art = value
End Set
End Property
Public Property pu() As String
Get
Return Me._pu
End Get
Set(ByVal value As String)
Me._pu = value
End Set
End Property
Public Property qté() As String
Get
Return Me._qté
End Get
Set(ByVal value As String)
Me._qté = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal a As String, ByVal p As Double, ByVal q As Integer)
Me._art = a
Me._pu = p
Me._qté = q
End Sub
Public Function identite() As String
Return Me._art & "||" & Me._pu & "||" & Me._qté
End Function

End Class

1 réponse

Utilisateur anonyme
30 mars 2011 à 14:50
Bonjour,

Une petite erreur au niveau de la propriété [ pu ] !

Module Module1

#Region " Variables "

    Dim list As New ArrayList

#End Region

#Region " Méthodes "

    Sub Main()
        Dim choix As Integer
        Console.WriteLine("==========MeNu==========")
        Console.WriteLine()
        Console.WriteLine(" I ajouter")
        Console.WriteLine(" II affichage ")
        Console.WriteLine(" III supprimer ")
        Console.WriteLine(" IV recherche ")
        Console.WriteLine()
        Console.WriteLine("========================")
        Do
            Console.WriteLine()
            Console.Write("entrer votre choix : ")
            choix = Console.ReadLine
            Console.WriteLine()
            Select Case (choix)
                Case 1
                    ajouter()
                Case 2
                    afficher()
                Case 3
                    supprimer()
                Case 4
                    recherche()
            End Select
        Loop While (choix <> 5)
    End Sub

    Sub ajouter()
        Dim o1 As article = New article
        Dim Ligne As String = String.Empty
        Console.Write("entrer l article :")
        o1.art = Console.ReadLine
        Console.Write("entrer l pu:")
        Ligne = Console.ReadLine.Replace(".", ",")
        o1.pu = CType(Ligne, Double)
        Console.Write("entrer l qté:")
        o1.qte = Console.ReadLine
        list.Add(o1)
    End Sub

    Public Sub afficher()
        Dim i As Integer = 0
        While i < list.Count
            Console.Out.WriteLine(CType(list.Item(i), article).identite)
            i = i + 1
        End While
    End Sub

    Public Sub supprimer()
        Dim m As Integer
        Console.Write(" entrer la position a supprimer : ")
        m = Console.ReadLine
        list.RemoveAt(m)
        Dim i As Integer = 0
        While i < list.Count
            Console.Out.WriteLine(CType(list.Item(i), article).identite)
            i = i + 1
        End While
    End Sub

    Public Sub recherche()
        Dim i As Integer = 0
        Dim m As String
        Dim trouve As Boolean = False
        Console.Write("entrez l'article a rechercher :")
        m = Console.ReadLine
        While i < list.Count - 1 And trouve = False
            If (CType(list.Item(i), article).art) = m Then
                trouve = True
                Console.Out.WriteLine(list(i).identite)
            End If
        End While
        If trouve = False Then
            Console.WriteLine("existe pa")
        End If
    End Sub

#End Region

End Module

Public Class article

#Region " Attributs "

    Private _art As String
    Private _pu As Double
    Private _qte As Integer

#End Region

#Region " Propriétés "

    Public Property art() As String
        Get
            Return Me._art
        End Get
        Set(ByVal value As String)
            Me._art = value
        End Set
    End Property

    Public Property pu() As Double
        Get
            Return Me._pu
        End Get
        Set(ByVal value As Double)
            Me._pu = value
        End Set
    End Property

    Public Property qte() As String
        Get
            Return Me._qte
        End Get
        Set(ByVal value As String)
            Me._qte = value
        End Set
    End Property

#End Region

#Region " Méthodes "

#Region " Constructeurs "

    Public Sub New()
    End Sub

    Public Sub New(ByVal a As String, ByVal p As Double, ByVal q As Integer)
        Me._art = a
        Me._pu = p
        Me._qte = q
    End Sub

#End Region

#Region " Fonctions "

    Public Function identite() As String
        Return Me._art & "||" & Me._pu & "||" & Me._qte
    End Function

#End Region

#End Region

End Class
'


Cdt

Lupin
0
re:

Il serait beaucoup plus sage de ne jamais utiliser les accents de la langue
française dans le code, je ne parle pas ici des messages dynamique envoyé
à l'utilisateur mais bien le code lui-même.

Tu remarqueras que j'ai enlevé le e accent aigue pour l'attribut [ _qté ] -> [ _qte ].

Cdt

Lupin
0