pardesi 0 Newbie Poster

how can i set that it will count also from the label that "how many rentals are overdue"

Structure rental
        Dim rentalid As Integer
        Dim familyname As String
        Dim Firstname As String
        Dim dateborrowed As Date
        Dim duedate As Date
        Public Overrides Function ToString() As String
            Return "   " & rentalid.ToString() & "   " & familyname & "   " & _
                   Firstname & "   " & "   " & dateborrowed & "   " & duedate & vbNewLine
        End Function
    End Structure

    Dim rentals(99) As rental      'memory locations for 100 (integer+integer) values
    Dim rentalcount As Integer = 0
    Dim overduerentalcount As Integer = 0
    Dim currentfile As String = ""
    Dim indexOfSelectedrental As Integer
    Dim indexofoverduerentals As Integer

    Private Sub btnAddRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddRecord.Click
        Try
            'validate rentalid
            If Not isValidID(txtRentalId.Text, 100000) Then
                MsgBox("Invalid Rental Id-Please Enter the validId")
                txtRentalId.SelectAll()
                txtRentalId.Focus()
            ElseIf isduplicateID(txtRentalId.Text) Then
                MsgBox("This rental is already issued.Please re-enter the RentalId")
                txtRentalId.SelectAll()
                txtRentalId.Focus()
                'validate date borrowed
            ElseIf Not isvaliddateborrowed(Date.Parse(dtpDateBorrowed.Text)) Then
                MsgBox("Please re-enter the Date Borrowed")
                'validate due date
            ElseIf Not isvalidDueDate(Date.Parse(dtpDueDate.Text), Date.Parse(dtpDateBorrowed.Text)) Then
                MsgBox("Please re-enter the valid Due Date")
            Else
                'good data
                rentalcount += 1
                'store the two parts of the rental
                Dim temp As rental
                temp.rentalid = CInt(txtRentalId.Text)
                temp.familyname = txtFamilyName.Text
                temp.Firstname = txtFirstName.Text
                temp.dateborrowed = Date.Parse(dtpDateBorrowed.Text)
                temp.duedate = Date.Parse(dtpDueDate.Text)


                Dim place As Integer = correctplace(temp)   'these 2 lines store the new rental
                lblOverdueRentals.Text = "  "
                InsertAt(place, temp)          'into the array in ascending order of rentalId
                'display all rentals
                displayallrentals()
                'reset the fields
                txtRentalId.Clear()
                txtFamilyName.Clear()
                txtFirstName.Clear()
                dtpDateBorrowed.Value = Today
                dtpDueDate.Value = Today
                txtRentalId.Focus()

            End If
        Catch ex As Exception
            MsgBox("Bad Data : " & ex.Message & vbNewLine & "Please Start Again")
            txtRentalId.SelectAll()
            txtRentalId.Focus()
        End Try

    End Sub
#Region "displays"
    'DISPLAY OVERDUE RENTALS IN THE LABEL

    Sub displayOverduerentals(ByVal overduerental As rental, ByVal daysoverdue As Integer)
    
        lblOverdueRentals.Text &= overduerental.rentalid.ToString() _
                                   & "                    " & _
                                    overduerental.duedate.ToString("d") & _
                                    "                          " & daysoverdue.ToString & vbNewLine


    End Sub
    Sub DisplayInListBox()
        lstRentals.Items.Clear()
        For i As Integer = 0 To rentalcount - 1
            lstRentals.Items.Add(rentals(i))
        Next

        displayallrentals()

    End Sub

#End Region


#Region "validation"

    Function isValidID(ByVal input As String, ByVal min As Integer) As Boolean
        Return IsNumeric(input) AndAlso isValidID(CDbl(input), min)
    End Function
    Function isvalidID(ByVal number As Double, ByVal min As Integer) As Boolean
        Return isinteger(number) AndAlso number >= min AndAlso number <= 999999
    End Function
    Function isinteger(ByVal number As Double) As Boolean
        Return CInt(number) = number
    End Function
    Function isduplicateID(ByVal input As String) As Boolean
        For i As Integer = 0 To rentalcount - 1
            If CInt(input) = rentals(i).rentalid Then
                Return True
            End If
        Next

        Return False
    End Function
    Function isvaliddateborrowed(ByVal dateEntered As Date)
        Dim daysTimeSpan As TimeSpan = dateEntered.Subtract(Today)
        Return daysTimeSpan.TotalDays <= 2 AndAlso daysTimeSpan.TotalDays >= -2
    End Function
    Function isvalidDueDate(ByVal duedate As Date, ByVal dateborrowed As Date)
        Dim daysTimesspanborrow As TimeSpan = duedate.Subtract(Today)
        Return daysTimesspanborrow.TotalDays <= 21 AndAlso daysTimesspanborrow.TotalDays >= -2 AndAlso _
                         duedate.Subtract(dateborrowed).TotalDays >= 0
    End Function
#End Region

#Region "insert into array logic"
    Public Function correctplace(ByVal newrental As rental) As Integer
        For i As Integer = 0 To rentalcount - 1 'search the array from position 0
            'loop until rentalId is < rentalId of array item already stored
            If newrental.rentalid < rentals(i).rentalid Then
                correctplace = i
                Exit Function
            End If
        Next
        correctplace = rentalcount - 1
    End Function

    Public Sub InsertAt(ByVal place As Integer, ByVal temp As rental)
        For i As Integer = rentalcount - 1 To place + 1 Step -1
            rentals(i) = rentals(i - 1)
        Next
        'insert where it belongs
        rentals(place) = temp
    End Sub
    Public Sub DeleteFromArray(ByVal indexOfRentalToDelete As Integer)
        For i As Integer = indexOfRentalToDelete To rentalcount - 1
            rentals(i) = rentals(i + 1)
        Next
        rentalcount -= 1
    End Sub

#End Region
    Sub displayallrentals()
        lstRentals.Items.Clear()
        lblOverdueRentals.Text = " "
        'for each item in array add item to listbox and label if is overdue
        For i = 0 To rentalcount - 1
            lstRentals.Items.Add(rentals(i))

            Dim daysOverdue As TimeSpan = Today.Subtract(rentals(i).duedate)
            If daysOverdue.TotalDays > 0 Then
                displayOverduerentals(rentals(i), daysOverdue.TotalDays)

            End If

        Next

        lblOverdueRentals.Text &= overduerentalcount.ToString & "  rentals overdue"
        

    End Sub

#Region "file handling"

    Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
        If dlgOpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            loadfromdiskfile(dlgOpenFile.FileName)
            displayallrentals()
            txtRentalId.SelectAll()
            txtRentalId.Focus()
        End If
    End Sub
    Private Sub loadfromdiskfile(ByVal filename As String)
        currentfile = filename
        FileOpen(1, filename, OpenMode.Input)
        Input(1, rentalcount)
        For i As Integer = 0 To rentalcount - 1
            Input(1, rentals(i).rentalid)
            Input(1, rentals(i).duedate)
        Next
        FileClose(1)
    End Sub

    Private Sub SaveToDiskFile(ByVal filename As String)
        currentfile = filename
        FileOpen(1, filename, OpenMode.Output)
        Write(1, rentalcount)
        For i As Integer = 0 To rentalcount - 1
            Write(1, rentals(i).rentalid)
            Write(1, rentals(i).duedate)
        Next
        FileClose(1)
    End Sub
    Sub DoSaveAs()
        If dlgSaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            SaveToDiskFile(dlgSaveFile.FileName)
        End If
    End Sub
    Private Sub mnuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSave.Click
        If currentfile = "" Then
            doSaveAs()
        Else
            SaveToDiskFile(currentfile)
        End If
    End Sub
#End Region