| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 
 | Public Class Form1
    Private myLoan As New Loanclass.Loan
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
    System.EventArgs) Handles MyBase.Load
        TextBox1.Text = myLoan.LoanAmount.ToString
        TextBox2.Text = myLoan.InterestRate.ToString
        TextBox3.Text = myLoan.Term.ToString
        TextBox4.Text = myLoan.Customer
 
 
        If File.Exists("SavedLoan.bin") Then
            Dim myFileStream As Stream = File.OpenRead("SavedLoan.bin")
            Dim deserializer As New BinaryFormatter()
            myLoan = CType(deserializer.Deserialize(myFileStream), _
    LoanClass.Loan)
            myFileStream.Close()
        End If
        TextBox1.Text = myLoan.LoanAmount.ToString
        TextBox2.Text = myLoan.InterestRate.ToString
        TextBox3.Text = myLoan.Term.ToString
        TextBox4.Text = myLoan.Customer
 
    End Sub
 
    Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As _
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
 
    End Sub
    'enregistrer les champs
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myLoan.LoanAmount = CType(TextBox1.Text, Double)
        myLoan.InterestRate = CType(TextBox2.Text, Double)
        myLoan.Term = CType(TextBox3.Text, Integer)
        myLoan.Customer = TextBox4.Text
 
        Dim myFileStream As Stream = File.Create("SavedLoan.bin")
        Dim serializer As New BinaryFormatter()
        serializer.Serialize(myFileStream, myLoan)
        myFileStream.Close()
    End Sub
End Class | 
Partager