Object reference not set to an instance of an object.+ Sourabh
-
Hi, Kindly see the codes below: On the next button I call ShowReconcileStatement. In ShowReconcileStatement I call GetGridTotal. When I call the GetGridTotal, Before it enters the procedure, I get an exception as : Object reference not set to an instance of an object. The code where the exception occurs I have underlined. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click Try tcBankReco.SelectedIndex = 1 ShowReconcileStatement() Catch ex As Exception End Try End Sub Private Sub ShowReconcileStatement() Try Dim i As Integer Dim bnkDep As Double = 0 Dim bnkWith As Double = 0 bnkWith = GetGridTotal(dgtmp, dgtmp.Cols(WITHDRAWLS).Index) bnkDep = GetGridTotal(dgtmp, dgtmp.Cols(DEPOSITS).Index) Catch ex As Exception End Try End Sub Private Function GetGridTotal(ByVal dg As C1.Win.C1FlexGrid.C1FlexGrid, ByVal col As Int16) As Double Try With dg Dim rg As CellRange = .GetCellRange(1, col, dg.Rows.Count - 1, col) Dim agg As String = .Aggregate(AggregateEnum.Sum, rg) Return CDbl(agg) End With Catch ex As Exception Return 0 ShowMessage(ex.Message, 30) Finally End Try End Function Please suggest..
Thanks and Regards,
-
Hi, Kindly see the codes below: On the next button I call ShowReconcileStatement. In ShowReconcileStatement I call GetGridTotal. When I call the GetGridTotal, Before it enters the procedure, I get an exception as : Object reference not set to an instance of an object. The code where the exception occurs I have underlined. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click Try tcBankReco.SelectedIndex = 1 ShowReconcileStatement() Catch ex As Exception End Try End Sub Private Sub ShowReconcileStatement() Try Dim i As Integer Dim bnkDep As Double = 0 Dim bnkWith As Double = 0 bnkWith = GetGridTotal(dgtmp, dgtmp.Cols(WITHDRAWLS).Index) bnkDep = GetGridTotal(dgtmp, dgtmp.Cols(DEPOSITS).Index) Catch ex As Exception End Try End Sub Private Function GetGridTotal(ByVal dg As C1.Win.C1FlexGrid.C1FlexGrid, ByVal col As Int16) As Double Try With dg Dim rg As CellRange = .GetCellRange(1, col, dg.Rows.Count - 1, col) Dim agg As String = .Aggregate(AggregateEnum.Sum, rg) Return CDbl(agg) End With Catch ex As Exception Return 0 ShowMessage(ex.Message, 30) Finally End Try End Function Please suggest..
Thanks and Regards,
Your dgtmp FlexGrid is not instantiated.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook "There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib "Animadvertistine, ubicumque stes, fumum recta in faciem ferri?"
-
Hi, Kindly see the codes below: On the next button I call ShowReconcileStatement. In ShowReconcileStatement I call GetGridTotal. When I call the GetGridTotal, Before it enters the procedure, I get an exception as : Object reference not set to an instance of an object. The code where the exception occurs I have underlined. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click Try tcBankReco.SelectedIndex = 1 ShowReconcileStatement() Catch ex As Exception End Try End Sub Private Sub ShowReconcileStatement() Try Dim i As Integer Dim bnkDep As Double = 0 Dim bnkWith As Double = 0 bnkWith = GetGridTotal(dgtmp, dgtmp.Cols(WITHDRAWLS).Index) bnkDep = GetGridTotal(dgtmp, dgtmp.Cols(DEPOSITS).Index) Catch ex As Exception End Try End Sub Private Function GetGridTotal(ByVal dg As C1.Win.C1FlexGrid.C1FlexGrid, ByVal col As Int16) As Double Try With dg Dim rg As CellRange = .GetCellRange(1, col, dg.Rows.Count - 1, col) Dim agg As String = .Aggregate(AggregateEnum.Sum, rg) Return CDbl(agg) End With Catch ex As Exception Return 0 ShowMessage(ex.Message, 30) Finally End Try End Function Please suggest..
Thanks and Regards,
Dot Net Jantu wrote:
bnkWith = GetGridTotal(dgtmp, dgtmp.Cols(WITHDRAWLS).Index)
Your code is assuming that
dgtmp.Cols(WITHDRAWLS)
is returning an object. If it doesn't return an object, meaning that it returnsNothing
, calling the Index property on it will throw this exception.A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007