Public Class MaClass Private _Tableau() As String Private _Propriete1 As String Public Property Tableau() As String() Get Return _Tableau End Get Set(ByVal value As String()) _Tableau = value End Set End Property Public Property Propriete1() As String Get Return _Propriete1 End Get Set(ByVal value As String()) _Propriete1 = value End Set End Property End Class
Dim X As New MaClass Call Rec(MaClass)
<Serializable()> Public Class Class_fichier_compte Private _ligne(,) As String Private _Type() As String Private _budget() As String Private _mdp As String
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'---------------------------------------------------------------------- ' Sub qui sérialise la class Class_fichier_compte puis l'enregistre en binaire dans le fichier passé en paramétre '---------------------------------------------------------------------- Public Sub save(ByVal fichier As String) Dim myFileStream As Stream = File.Create(fichier) ' création d'un nouveau fichier à chaque sauvegarde Dim serializer As New BinaryFormatter serializer.Serialize(myFileStream, Me) myFileStream.Close() End Sub ' '---------------------------------------------------------------------- ' fonction qui lit le fichier sérialisé de class Class_fichier_compte et qui retourne les tableaux a n dimensions '---------------------------------------------------------------------- Public Function load(ByVal fichier As String) As Boolean Dim lecture As New Class_fichier_compte Try Dim myFileStream As Stream = File.OpenRead(fichier) Dim deserializer As New BinaryFormatter() lecture = CType(deserializer.Deserialize(myFileStream), Class_fichier_compte) myFileStream.Close() Me.mdp = lecture.mdp Me.types = lecture.types Me.budgets = lecture.budgets Me.lignes = lecture.lignes Return True Catch ex As Exception MsgBox("erreur de lecture, désolé", MsgBoxStyle.Critical) Return False End Try End Function
<Serializable()> _ Class TestSerialisable ' Private _Text As String ' Property Text() As String Get Return _Text End Get Set(ByVal value As String) _Text = value End Set End Property ' Public Function loadByFile(ByVal fichier As String) As TestSerialisable ' Dim myFileStream As Stream = Nothing ' Try ' myFileStream = New FileStream(fichier, _ FileMode.Open, _ FileAccess.Read, _ FileShare.ReadWrite) ' Dim deserializer As New BinaryFormatter() ' Return CType(deserializer.Deserialize(myFileStream), TestSerialisable) ' Catch ex As Exception ' MessageBox.Show("Impossible de restaurer les valeurs, le fichier à été supprimé ou est utilisé par une autre application.", _ "Erreur de lecture", _ MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation) ' Return Nothing ' Finally ' myFileStream.Close() ' End Try '' End Function Public Sub save(ByVal fichier As String) ' If IO.File.Exists(fichier) Then ' Try ' IO.File.Delete(fichier) ' Catch ex As Exception ' MessageBox.Show("Impossible d'enregistrer les valeurs, le fichier est en cours d'utilisation par une autre application.", _ "Erreur", _ MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation) ' Exit Sub ' End Try ' End If ' Dim myFileStream As Stream = Nothing ' Try ' myFileStream = New FileStream(fichier, _ FileMode.Create, _ FileAccess.Write, _ FileShare.None) ' Dim serializer As New BinaryFormatter ' serializer.Serialize(myFileStream, Me) ' Catch ex As Exception ' MessageBox.Show("Impossible d'enregistrer les valeurs, dans le fichier. Vérifiez que votre compte utilisateur possède les droits requis.", _ "Erreur d'accès en écriture", _ MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation) ' Finally ' myFileStream.Close() ' End Try '' End Sub End Class
Dim T As New TestSerialisable T.Text = "Trahiudhsuidh" T.save("c:\test.bin") T = T.loadByFile("c:\test.bin")
'---------------------------------------------------------------------- ' enregistrement des tableaux & lignes dans la class mon_compte '---------------------------------------------------------------------- Dim tableau(ListView1.Items.Count - 1, ListView1.Columns.Count - 1) As String Dim liste As New ListViewItem For ligne As Integer = 0 To ListView1.Items.Count - 1 liste = ListView1.Items(ligne) For Colonne As Integer = 0 To ListView1.Columns.Count - 1 tableau(ligne, Colonne) = liste.SubItems(Colonne).Text Next Next 'recherche si le budget et le type exist déja ou pas For ligne As Integer = 0 To ListView1.Items.Count - 1 liste = ListView1.Items(ligne) Dim recherche_type As String = liste.SubItems(2).Text For type As Integer = 0 To choix_type.Length - 1 Next Dim recherche_budget As String = liste.SubItems(3).Text For budget As Integer = 0 To choix_budget.Length - 1 Next Next ligne ' attribut les valeurs des différents tableaux à sérialiser ! merci Mayzz ^^ mon_compte.lignes = tableau mon_compte.budgets = choix_budget mon_compte.types = choix_type mon_compte.save(ma_sauvegarde)
' lecture des tableaux des combobox dasn le load de la form nouvelle opération Combo_budget.DataSource = principal.mon_compte.budgets Combo_type.DataSource = principal.mon_compte.types
Private Sub Combo_budget_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Combo_budget.SelectedIndexChanged ' fait rien End Sub Private Sub Combo_budget_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo_budget.TextChanged ' fait rien End Sub Private Sub Combo_budget_DataSourceChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Combo_budget.DataSourceChanged ' fait rine non plus ' l code principal.mon_compte.budgets Combo_budget.DataSource End Sub
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown If e.KeyCode = Keys.Delete Then If ComboBox1.Items.Contains(Me.ComboBox1.Text) Then Me.ComboBox1.Items.Remove(Me.ComboBox1.Text) End If ElseIf e.KeyCode = Keys.Enter AndAlso Not ComboBox1.Items.Contains(Me.ComboBox1.Text) Then Me.ComboBox1.Items.Add(Me.ComboBox1.Text) End If End Sub
Not tableau.Items.Contains(Me.ComboBox1.Text) Then tableau.items.add (Me.ComboBox1.Text) ' puis combobox1.datasource = tableau
If Not principal.mon_compte.budgets.Contains(Combo_budget.SelectedText) Then principal.mon_compte.budgets.add(Combo_budget.SelectedText) End If
principal.mon_compte.budgets &= Combo_budget.SelectedTextnon plus
'transférer dans les tableaux de la class mon_compte.types et budget les modifs éventuels des combobox If Not Combo_budget.Items.Contains(Me.Combo_budget.Text) Then 'si detection d'une nouvelle saisie ' l'enregistre dans les tableaux de la class mon_compte.budget en redimensionnant le tableau ReDim Preserve principal.mon_compte.budgets(principal.mon_compte.budgets.Length) principal.mon_compte.budgets(principal.mon_compte.budgets.Length - 1) = Me.Combo_budget.Text End If If Not Combo_type.Items.Contains(Me.Combo_type.Text) Then 'si detection d'une nouvelle saisie ' l'enregistre dans les tableaux de la class mon_compte.type ReDim Preserve principal.mon_compte.types(principal.mon_compte.types.Length) principal.mon_compte.types(principal.mon_compte.types.Length - 1) = Me.Combo_type.Text End If
Private Sub Combo_budget_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Combo_budget.KeyDown If e.KeyCode = Keys.Delete Then If Combo_budget.Items.Contains(Me.Combo_budget.Text) Then Me.Combo_budget.Items.Remove(Me.Combo_budget.Text) End If End Sub
Private Sub Combo_budget_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Combo_budget.KeyDown If e.KeyCode = Keys.Delete Then If Combo_budget.Items.Contains(Me.Combo_budget.Text) Then ElseIf MessageBox.Show("confirmer la suppression du budget" & vbCrLf & Combo_budget.Text & " ?", "Suppression" _ , MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then End If End If 'Me.Combo_budget.Items.Remove(Me.Combo_budget.Text) End Sub