Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String to decimal

Status
Not open for further replies.
Apr 3, 2005
32
US
I receive the following error message when trying to convert a string into decimal.
"Object reference not set to an instance of an object. "

And this is the line of code that generated the error msg.
Dim DAmnt As Decimal
DAmnt = Convert.ToDecimal(txtDAmnt.Text)

And this is the rest of my code:


Sub DataList_UpdateCommand(ByVal sender As Object, ByVal e As DataListCommandEventArgs)


Dim txtDRowID As Label = e.Item.FindControl("RowID")
Dim txtDAcctUnit As Label = e.Item.FindControl("DebAcctUnit")
Dim txtDAcctNum As Label = e.Item.FindControl("DebAcctNum")
Dim txtDActivity As Label = e.Item.FindControl("DebActivity")
Dim txtDAcctCat As Label = e.Item.FindControl("DebAcctCat")
Dim txtDInd As Label = e.Item.FindControl("DebitInd")
Dim txtDAmnt As Label = e.Item.FindControl("DebitAmt")
Dim txtDUnits As Label = e.Item.FindControl("DebUnits")
Dim txtDDesc As Label = e.Item.FindControl("DebDesc")
Dim txtDRef As Label = e.Item.FindControl("DebRef")
Dim txtCAcctUnit As Label = e.Item.FindControl("CredAcctUnit")
Dim txtCAcctNum As Label = e.Item.FindControl("CredAcctNum")
Dim txtCActivity As Label = e.Item.FindControl("CredActivity")
Dim txtCAcctCat As Label = e.Item.FindControl("CredAcctCat")
Dim txtCInd As Label = e.Item.FindControl("CreditInd")
Dim txtCAmnt As Label = e.Item.FindControl("CredAmnt")
Dim txtCUnits As Label = e.Item.FindControl("CredUnits")
Dim txtCDesc As Label = e.Item.FindControl("CredDesc")
Dim txtCRef As Label = e.Item.FindControl("CredRef")

Dim DRowID As String = txtDRowID.Text
Dim DAcctUnit As String =txtDAcctUnit.Text
Dim DAcctNum As String = txtDAcctNum.Text
Dim DActivity As String = txtDActivity.Text
Dim DAcctCat As String = txtDAcctCat.Text
Dim DInd As String = txtDInd.Text
Dim DAmnt As Decimal
DAmnt = Convert.ToDecimal(txtDAmnt.Text)
Dim DUnits As Decimal = txtDUnits.Text
Dim DDesc As String = txtDDesc.Text
Dim DRef As String = txtDRef.Text
Dim CAcctUnit As String = txtCAcctUnit.Text
Dim CAcctNum As String = txtCAcctNum.Text
Dim CActivity As String = txtCActivity.Text
Dim CAcctCat As String = txtCAcctCat.Text
Dim CInd As String = txtCInd.Text
Dim CAmnt As Decimal = txtCAmnt.Text
Dim CUnits As Decimal = txtCUnits.Text
Dim CDesc As String = txtCDesc.Text
Dim CRef As String = txtCRef.Text



CorrectionView.RowFilter = "RowID='" & DRowID & "'"
If CorrectionView.Count > 0 Then
CorrectionView.Delete(0)
End If
CorrectionView.RowFilter = ""
Dim dr As DataRow = CorrectionTable.NewRow()
dr(0) = CAcctUnit
dr(1) = CAcctNum
dr(2) = CActivity
dr(3) = CAcctCat
dr(4) = CInd
dr(5) = CAmnt
dr(6) = CUnits
dr(7) = CDesc
dr(8) = CRef
dr(9) = DAcctUnit
dr(10) = DAcctNum
dr(11) = DActivity
dr(12) = DAcctCat
dr(13) = DInd
dr(14) = DAmnt
dr(15) = DUnits
dr(16) = DDesc
dr(17) = DRef
CorrectionTable.Rows.Add(dr)
dlCorrection.EditItemIndex = -1
BindList()
End Sub
 
I belive you need the NEW keyword:

change
Code:
Dim txtDAmnt As Label = e.Item.FindControl("DebitAmt")
To
Code:
Dim txtDAmnt As [b]New[/b] Label = e.Item.FindControl("DebitAmt")

Jim
 
then the findcontrol is failing .. step through your code and stop on one of those lines and see what the value of the object is
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top