Sathya Narayan

Sathya Narayan

  • NA
  • 155
  • 65.5k

Opening Balance and Closing balance

Apr 2 2015 2:13 AM
I have an issue with the calculation of opening balance and closing balance.When i make the text change event it should show the NextDayOpeningBal amount but it show the outstanding amount.I am making the textchange event through the dropdownbox to textbox and calculating the outstanding amount-cashreceived.It must show the NextDayOpeningBal amount and if i do calculation of opening balance-cash received i am getting negative value.This is the code i am using.

Private Sub Label6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.TextChanged
        On Error Resume Next
        For i = OA To OB
            txtobamt.Text = OA
            txtcashrecvd.Text = PA
            txtcb.Text = OB
            conn = New SqlConnection(cnString)
            Dim Sql As String = "Select distinct(slno),OB,OA,PA from Balance_view where slno='" + Label6.Text + "' and stu='A' order by OA "
            conn.Open()


            Dim cmd As New SqlCommand(Sql, conn)
            Dim rs As SqlDataReader
            rs = cmd.ExecuteReader
            While rs.Read
                txtobamt.Text = (rs(2).ToString())
                OA = Val(OB) - Val(PA)
            End While
            rs.Close()


        Next



       




End Sub


Private Sub txtobamt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtobamt.TextChanged


        txtcb.Text = Val(txtobamt.Text)  -Val(txtcashrecvd.Text)


    End Sub


    Private Sub txtcashrecvd_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcashrecvd.TextChanged
        txtcb.Text = Val(txtobamt.Text)  -Val(txtcashrecvd.Text)
    End Sub


    Private Sub txtcb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcb.TextChanged
        txtcb.Text = Val(txtobamt.Text)  -Val(txtcashrecvd.Text)
    End Sub


 Private Sub DataGridView2_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.CellContentClick
        On Error Resume Next
        txtobamt.Text = OA
        txtcashrecvd.Text = PA
        txtcb.Text = OB
        Dim i As Integer
        Dim CurrentDayCash As Decimal
        Dim ClosingBal As Decimal
        Dim NextDayOpeningBal As Decimal

        For i = 0 To j
            If i = j Then i -= 1
            With Me.DataGridView2
                OA = .Rows(i).Cells(4).Value
                PA = .Rows(i).Cells(3).Value
                OB = Val(PA) - Val(OA)
                .Rows(i + 1).Cells(4).Value = OB
            End With
            If i + 1 = j Then Exit For
        Next

    End Sub

can any one help me plz?



Answers (1)