Code laid

XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012 - 8 nov. 2006 à 04:27
XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012 - 8 nov. 2006 à 15:58
Voici le code d'une propriété , je suis bien curieu de savoir s'il exite des "truc" pour faire mieu.

#Region "Propriété infodroits()          "

    ' Appelant(Get/Set): btnValider.Click / ListView1.MouseDoubleClick.
    Private Property infodroits() As String
        Get
            Dim droits As String = Nothing
            droits +IIf(ChkPG.Checked True, "G", "_").ToString            droits +IIf(ChkPR.Checked True, "R", "_").ToString            droits +IIf(ChkDL.Checked True, "L", "_").ToString            droits +IIf(ChkDE.Checked True, "E", "_").ToString            droits +IIf(ChkDM.Checked True, "M", "_").ToString            droits +IIf(ChkDS.Checked True, "S", "_").ToString            droits +IIf(ChkPD.Checked True, "D", "_").ToString

            If droits = "_______" Then
                Throw New Exception("Aucun privilège ou droit sélectionner")
            End If

            Return droits
        End Get
        Set(ByVal strDroits As String)
            Dim droits() As Char = strDroits.ToCharArray
            Dim validchar() As Char = "GRLEMSD".ToCharArray

            Try
                ChkPG.Checked CBool(IIf(droits(0) validchar(0), True, False))                ChkPR.Checked CBool(IIf(droits(1) validchar(1), True, False))                ChkDL.Checked CBool(IIf(droits(2) validchar(2), True, False))                ChkDE.Checked CBool(IIf(droits(3) validchar(3), True, False))                ChkDM.Checked CBool(IIf(droits(4) validchar(4), True, False))                ChkDS.Checked CBool(IIf(droits(5) validchar(5), True, False))                ChkPD.Checked CBool(IIf(droits(6) validchar(6), True, False))

                For i As Integer = 0 To 6
                    If droits(i) <> "_" AndAlso droits(i) <> validchar(i) Then
                        SBP_info.Text = "Une donnée non conforme a été trouvé dans le format des droits de cette utilisateur"
                        Exit For
                    End If
                Next

            Catch Exp As Exception
                Throw New Exception(Exp.Message)

            End Try

        End Set
    End Property

12 réponses

XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012
8 nov. 2006 à 11:03
J'ai apporté cette amélioration

Try
                ChkPG.Checked (droits(0) "G")                ChkPR.Checked (droits(1) "R")                ChkDL.Checked (droits(2) "L")                ChkDE.Checked (droits(3) "E")                ChkDM.Checked (droits(4) "M")                ChkDS.Checked (droits(5) "S")                ChkPD.Checked (droits(6) "D")
0
cboulas Messages postés 2641 Date d'inscription mercredi 2 juin 2004 Statut Membre Dernière intervention 8 janvier 2014 16
8 nov. 2006 à 12:08
Re ^^

Retire le True car checked te renvoi déjà true ou false donc sélection automatique
puis retire le tostring car dans tes IIf tu renvoi déjà du string avec les ""

            droits &= IIf(ChkPG.Checked, "G", "_")
            droits &= IIf(ChkPR.Checked, "R", "_")
            droits &= IIf(ChkDL.Checked, "L", "_")
            droits &= IIf(ChkDE.Checked, "E", "_")
            droits &= IIf(ChkDM.Checked, "M", "_")
            droits &= IIf(ChkDS.Checked, "S", "_")
            droits &= IIf(ChkPD.Checked, "D", "_")

Chris...
Web : Firstruner
0
cboulas Messages postés 2641 Date d'inscription mercredi 2 juin 2004 Statut Membre Dernière intervention 8 janvier 2014 16
8 nov. 2006 à 12:12
au passage :

Dim droits As String = IIf(ChkPG.Checked, "G", "_")
            droits &= IIf(ChkPR.Checked, "R", "_")
            droits &= IIf(ChkDL.Checked, "L", "_")
            droits &= IIf(ChkDE.Checked, "E", "_")
            droits &= IIf(ChkDM.Checked, "M", "_")
            droits &= IIf(ChkDS.Checked, "S", "_")
            droits &= IIf(ChkPD.Checked, "D", "_")

Chris...
Web : Firstruner
0
NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 159
8 nov. 2006 à 12:39
Bonjour

en .NET 2, poutr iif : ajoute cette méthode (dans un module par ex) :


public function IIF(of T)(Byval pBool as boolean,byval pValue1 as T, Byval pValue2 as T) as T

    if pBool then

       return pValue1

    else

       Return pValue2

    End if

End function


Comme cela, plus besoin de transtyper la sortie.

Il est plus facile de batiser quelqu'un que de la convertir. (surtout en programmation)
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)

<fon></fon>
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012
8 nov. 2006 à 12:51
cboula, j'ai bien enlevé le = true, cependant le .tostring ne s'enleve pas en option stricte, IIF retourne un objet et non un string..... c'est l'erreur que sa me donne.
0
NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 159
8 nov. 2006 à 12:54
Bonjour

Justement, si tu bosse en .NET2 (2005), tu met la fonction que j'ai écrite et tu l'utilise de cette manière :


Dim lStr as string=iif(a=b,"a","_")


on en forçant :


Dim lStr as string=iif(of string)(a=b,"a","_")

Il est plus facile de batiser quelqu'un que de la convertir. (surtout en programmation)
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)

<fon></fon>
0
XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012
8 nov. 2006 à 13:09
Ta solution est très intéressante je l'avoue et va m'etre grandement utile dans le futur. Cependant, je préfere éviter l'utilisation d'une fonction de ce genre dans un code qui va service d'Exemple pour des fin de lisibilité pour les débutants.

Je suis en trein d'essayer une technique qui resemble à cela:

            Dim strDroits As String  = "_______"
           
            With strDroits
                if ChkPG.Checked then  .char(0) = "G"
                if ChkPR.Checked then  .char(1) = "R"
                if ChkPL.Checked then  .char(2) = "L"
                if ChkPE.Checked then  .char(3) = "E"
                if ChkPM.Checked then  .char(4) = "M"
                if ChkPS.Checked then  .char(5) = "S"
                if ChkPD.Checked then  .char(6) = "D"
             End With

            If strDroits = "_______" Then
                Throw New Exception("Aucun privilège ou droit sélectionner")
            End If

Bien entendu .char() n'existe pas, mais il doit bien y avoir moyen de remplacer simplement un sous élément d'apres son index.....
0
NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 159
8 nov. 2006 à 13:25
Bonjour

Dim ltChars(6) as char


for i as integer=0 to 6

    ltchars(i)="_"c

next


With strDroits

                if ChkPG.Checked then  .char(0) = "G"

                if ChkPR.Checked then  .char(1) = "R"

                if ChkPL.Checked then  .char(2) = "L"

                if ChkPE.Checked then  .char(3) = "E"

                if ChkPM.Checked then  .char(4) = "M"

                if ChkPS.Checked then  .char(5) = "S"

                if ChkPD.Checked then  .char(6) = "D"

             End With

Dim lStr as string=convert.tostring(ltchars)


Pas testé, mais ça me semble correcte.

Il est plus facile de batiser quelqu'un que de la convertir. (surtout en programmation)
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)

<fon></fon>
0
NHenry Messages postés 15114 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 4 mai 2024 159
8 nov. 2006 à 13:28
Bonjour

j'ai posté trop vite :


if ChkPG.Checked then  ltchars(0) = "G"

if ChkPR.Checked then  ltchars(1) = "R"

if ChkPL.Checked then  ltchars(2) = "L"

if ChkPE.Checked then  ltchars(3) = "E"

if ChkPM.Checked then  ltchars(4) = "M"

if ChkPS.Checked then  ltchars(5) = "S"

if ChkPD.Checked then  ltchars(6) = "D"

          
Il est plus facile de batiser quelqu'un que de la convertir. (surtout en programmation)
NHenry (VB6, VBA excel, VB.NET, C++, C#.Net)

<fon></fon>
0
cboulas Messages postés 2641 Date d'inscription mercredi 2 juin 2004 Statut Membre Dernière intervention 8 janvier 2014 16
8 nov. 2006 à 14:35
Juste une petite idée qui me passe par la tête :

tu recréer une classe avec l'héritage de listviewitem
et tu y insère une fonction de recherche telle que :

function CheckSecurity(Lbl as string) as string
      for i as int32 = 0 to me.SubItems.Count -1
               if me.sibitems(i).text = Lbl then return Lbl
         loop

end function

comme tu peux faire y faire une enumération telle que :



Enum
SecurID

R



L


E


M


S


D



End



Enum

où R=0, L=1, E=2, etc... si tu ajout 1 au retour de l'enumération tu tombe forcément sur ton 1 pour le R, etc...






Chris...


Web :
Firstruner =
0
XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012
8 nov. 2006 à 15:56
Au lieu de
Dim ltChars(6) as char

for i as integer=0 to 6
    ltchars(i)="_"c
next
c'est beaucoup mieu:

Dim ltChars(6) as char{"_","_","_","_","_","_"}

Au moins ces standards d'apres les normes de programmation des templates.

En fait je cherche surtout a trouver comment changer une seul lettre de ma string a partir de son index...
0
XGuarden Messages postés 259 Date d'inscription dimanche 14 juillet 2002 Statut Membre Dernière intervention 17 août 2012
8 nov. 2006 à 15:58
Ou encore
Dim ltChars() As Char = "______".ToCharArray
0
Rejoignez-nous