addition problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek

    #1

    addition problem

    I am having a problem updating the main table (2nd set of
    code) based on the total of all details entered (1st set
    of code). It seems to be off by less than a dollar. I
    thought it was a decimal issue but all my ctypes are set
    to decimal. I am resetting all my textfields to "" after
    adding the detail information. Any help would be
    appreciated.

    Here's the code:

    'this updates the details table with the amounts

    Dim lastid As Integer

    SqlSelectComman d12.Parameters( "@userid").Valu e =
    CType(lbluserid .Text, Integer)

    SqlDataAdapter1 2.Fill(Dsmaxtrx id1)

    lblmaxtrxid.Dat aBind()



    lastid = CType(lblmaxtrx id.Text, Integer)

    'set details information and save

    txtItem1.Visibl e = True

    txtqty1.Visible = True

    txtunit1.Visibl e = True





    Dim qty1 As Decimal

    Dim unit1 As Decimal



    qty1 = CType(txtqty1.T ext, Decimal)

    unit1 = CType(txtunit1. Text, Decimal)

    lbleucost.Text = qty1 * unit1

    Dim EUC As Decimal

    EUC = CType(lbleucost .Text, Decimal)



    If txtEC.Text = "" Then

    txtEC.Text = lbleucost.Text

    Else

    Dim ectext As Decimal

    ectext = CType(txtEC.Tex t, Decimal)

    txtEC.Text = ectext + EUC

    End If





    Dim ec As Decimal

    ec = CType(lbleucost .Text, Decimal)

    SqlUpdateComman d2.Parameters(" @trxid").Value =
    lastid

    SqlUpdateComman d2.Parameters(" @desc").Value =
    txtItem1.Text

    SqlUpdateComman d2.Parameters(" @qty").Value = qty1

    SqlUpdateComman d2.Parameters(" @uc").Value = unit1

    SqlUpdateComman d2.Parameters(" @ec").Value = ec

    SqlConnection1. Open()

    SqlUpdateComman d2.ExecuteNonQu ery()

    SqlConnection1. Close()







    txtEC.Visible = True



    ShowFields()

    txtItem1.Text = ""

    txtqty1.Text = ""

    txtunit1.Text = ""

    lbleucost.Text = ""

    txtItem1.TabInd ex = 1

    txtqty1.TabInde x = 2

    txtunit1.TabInd ex = 3

    Button1.TabInde x = 4

    resetTabs()

    BindDetails()









    ' Updates the main table with the total estimated charges

    Dim inttrx As Integer

    inttrx = CType(lblmaxtrx id.Text, Integer)

    SqlUpdateComman d5.Parameters(" @ec").Value =
    txtEC.Text

    SqlUpdateComman d5.Parameters(" @tid").Value =
    inttrx

    SqlConnection1. Open()

    SqlUpdateComman d5.ExecuteNonQu ery()

    SqlConnection1. Close()

  • Derek

    #2
    addition problem

    I forgot to mention earlier...

    This is what specifically is occurring.
    First entry goes in fine.
    The next entry if it is a whole goes in fine and adds
    properly.
    Anytime you put another entry in that has cents it adds
    the whole number but not the cents.



    [color=blue]
    >-----Original Message-----
    >I am having a problem updating the main table (2nd set[/color]
    of[color=blue]
    >code) based on the total of all details entered (1st set
    >of code). It seems to be off by less than a dollar. I
    >thought it was a decimal issue but all my ctypes are set
    >to decimal. I am resetting all my textfields to ""[/color]
    after[color=blue]
    >adding the detail information. Any help would be
    >appreciated.
    >
    >Here's the code:
    >
    >'this updates the details table with the amounts
    >
    >Dim lastid As Integer
    >
    > SqlSelectComman d12.Parameters( "@userid").Valu e =
    >CType(lbluseri d.Text, Integer)
    >
    > SqlDataAdapter1 2.Fill(Dsmaxtrx id1)
    >
    > lblmaxtrxid.Dat aBind()
    >
    >
    >
    > lastid = CType(lblmaxtrx id.Text, Integer)
    >
    > 'set details information and save
    >
    > txtItem1.Visibl e = True
    >
    > txtqty1.Visible = True
    >
    > txtunit1.Visibl e = True
    >
    >
    >
    >
    >
    > Dim qty1 As Decimal
    >
    > Dim unit1 As Decimal
    >
    >
    >
    > qty1 = CType(txtqty1.T ext, Decimal)
    >
    > unit1 = CType(txtunit1. Text, Decimal)
    >
    > lbleucost.Text = qty1 * unit1
    >
    > Dim EUC As Decimal
    >
    > EUC = CType(lbleucost .Text, Decimal)
    >
    >
    >
    > If txtEC.Text = "" Then
    >
    > txtEC.Text = lbleucost.Text
    >
    > Else
    >
    > Dim ectext As Decimal
    >
    > ectext = CType(txtEC.Tex t, Decimal)
    >
    > txtEC.Text = ectext + EUC
    >
    > End If
    >
    >
    >
    >
    >
    > Dim ec As Decimal
    >
    > ec = CType(lbleucost .Text, Decimal)
    >
    > SqlUpdateComman d2.Parameters(" @trxid").Value =
    >lastid
    >
    > SqlUpdateComman d2.Parameters(" @desc").Value =
    >txtItem1.Tex t
    >
    > SqlUpdateComman d2.Parameters(" @qty").Value = qty1
    >
    > SqlUpdateComman d2.Parameters(" @uc").Value = unit1
    >
    > SqlUpdateComman d2.Parameters(" @ec").Value = ec
    >
    > SqlConnection1. Open()
    >
    > SqlUpdateComman d2.ExecuteNonQu ery()
    >
    > SqlConnection1. Close()
    >
    >
    >
    >
    >
    >
    >
    > txtEC.Visible = True
    >
    >
    >
    > ShowFields()
    >
    > txtItem1.Text = ""
    >
    > txtqty1.Text = ""
    >
    > txtunit1.Text = ""
    >
    > lbleucost.Text = ""
    >
    > txtItem1.TabInd ex = 1
    >
    > txtqty1.TabInde x = 2
    >
    > txtunit1.TabInd ex = 3
    >
    > Button1.TabInde x = 4
    >
    > resetTabs()
    >
    > BindDetails()
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >' Updates the main table with the total estimated charges
    >
    >Dim inttrx As Integer
    >
    > inttrx = CType(lblmaxtrx id.Text, Integer)
    >
    > SqlUpdateComman d5.Parameters(" @ec").Value =
    >txtEC.Text
    >
    > SqlUpdateComman d5.Parameters(" @tid").Value =
    >inttrx
    >
    > SqlConnection1. Open()
    >
    > SqlUpdateComman d5.ExecuteNonQu ery()
    >
    > SqlConnection1. Close()
    >
    >.
    >[/color]

    Comment

    • Felix Wang

      #3
      RE: addition problem

      Hi Derek,

      Thanks for posting.

      I have reviewed the code. Do you mean that the txtEC.Text will lose its
      decimal fraction or the corresponding value in the SQL Server database will
      lose its decimal fraction after updaing?

      If txtEC.Text is losing the decimal fraction, maybe we can set some break
      points in the method and track the variables. In addition, we may also try
      to simplify the code to isolate the problem here. For example, I simplify
      the code to the following:

      Dim qty1 As Decimal
      Dim unit1 As Decimal

      qty1 = CType(txtqty1.T ext, Decimal)
      unit1 = CType(txtunit1. Text, Decimal)
      lbleucost.Text = qty1 * unit1

      Dim EUC As Decimal
      EUC = CType(lbleucost .Text, Decimal)

      If txtEC.Text = "" Then
      txtec.Text = lbleucost.Text
      Else
      Dim ectext As Decimal
      ectext = CType(txtEC.Tex t, Decimal)
      txtEC.Text = ectext + EUC
      End If

      txtQty1.Text = ""
      txtUnit1.Text = ""
      lbleucost.Text = ""

      There seems to be no problem with this simplified code on my side. I am
      using VS.Net 2003. However, I am not very sure why we need to use the label
      "lbleucost" here. It does not seem to display anything.

      If there is no problem with txtEC.Text and the value in the database loses
      its decimal fraction, may be the problem here is with the update command or
      on the database side.

      I hope this makes sense to you.

      Regards,

      Felix Wang
      Microsoft Online Partner Support
      Get Secure! - www.microsoft.com/security
      This posting is provided "as is" with no warranties and confers no rights.

      Comment

      Working...