'Bonjour,
'Ci-dessous une méthode pour enregistrer toutes les options cochées ou sélectionnées par l'utilisateur :
'tous les controles sont scannés (jusqu'à 8 niveaux) pour vérifier les options choisies
'A noter que le développeur doit saisir "1" dans le tag des controles (combobox, checkboxes...) qu'il souhaite sauvegarder
'Il faut sauvegarder le tableau options_demarrage() dans votre sauvegarde avec les autres éléments de votre sauvegarde
'la fonction mettre_a_jour_les_options_a_la_sauvegarde retourne le tableau à enregistrer et la méthode chargement_options charge le tableau d'options
'Bien cordialement
Sub chargement_options(options_demarrage() As String)
Dim sz(0) As String
For u = 0 To options_demarrage.Count - 1
If options_demarrage(u) IsNot Nothing Then
sz = options_demarrage(u).Split(";")
If sz IsNot Nothing Then
Call mettre_a_jour_le_control_au_demarrage(sz(0), sz(1))
End If
End If
Next
Application.DoEvents()
End Sub
Sub mettre_a_jour_le_control_au_demarrage(nom As String, text As String)
For Each c1 In Controls
If c1.name.ToString = nom Then
type_de_control(c1, text)
End If
For Each c2 In c1.Controls
If c2.name.ToString = nom Then
type_de_control(c2, text)
End If
For Each c3 In c2.Controls
If c3.name.ToString = nom Then
type_de_control(c3, text)
End If
For Each c4 In c3.Controls
If c4.name.ToString = nom Then
type_de_control(c4, text)
End If
For Each c5 In c4.Controls
If c5.name.ToString = nom Then
type_de_control(c5, text)
End If
For Each c6 In c5.Controls
If c6.name.ToString = nom Then
type_de_control(c6, text)
End If
For Each c7 In c6.Controls
If c7.name.ToString = nom Then
type_de_control(c7, text)
End If
For Each c8 In c7.Controls
If c8.name.ToString = nom Then
type_de_control(c8, text)
End If
Next
Next
Next
Next
Next
Next
Next
Next
End Sub
Sub type_de_control(ByRef co_, ByVal text_)
If TypeOf co_ Is Label Then
co_.text = text_
End If
If TypeOf co_ Is ComboBox Then
co_.selecteditem = text_
End If
If TypeOf co_ Is CheckBox Then
If text_ = "True" Then
co_.checked = True
Else
co_.checked = False
End If
End If
If TypeOf co_ Is RadioButton Then
If text_ = "True" Then
co_.checked = True
Else
co_.checked = False
End If
End If
End Sub
Function mettre_a_jour_les_options_a_la_sauvegarde()
'TOUS LES CONTROLES QUI ONT LE CHIFFRE 1 DANS LEUR TAG
'SERONT ENREGISTRES
Dim sz(10000) As String
Dim nz As Integer = 0
For Each c1 In Me.Controls
If c1.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c1)
End If
For Each c2 In c1.Controls
If c2.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c2)
End If
For Each c3 In c2.Controls
If c3.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c3)
End If
For Each c4 In c3.Controls
If c4.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c4)
End If
For Each c5 In c4.Controls
If c5.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c5)
End If
For Each c6 In c5.Controls
If c6.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c6)
End If
For Each c7 In c6.Controls
If c7.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c7)
End If
For Each c8 In c7.Controls
If c8.tag = "1" Then
nz = nz + 1
sz(nz) = retourner_la_valeur_du_control(c8)
End If
Next
Next
Next
Next
Next
Next
Next
Next
If nz > 0 Then
ReDim Preserve sz(nz)
If sz IsNot Nothing Then
Return sz
End If
Else
End If
End Function
Function retourner_la_valeur_du_control(ByVal co_)
If TypeOf co_ Is Label Then
Return co_.name & ";" & co_.text
End If
If TypeOf co_ Is ComboBox Then
If co_.selectedindex > -1 Then Return co_.name & ";" & co_.selecteditem.ToString
End If
If TypeOf co_ Is CheckBox Then
Return co_.name & ";" & co_.checked.ToString
End If
If TypeOf co_ Is RadioButton Then
Return co_.name & ";" & co_.checked.ToString
End If
End Function
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.