Results 1 to 3 of 3

Thread: [RESOLVED] SUM of Textboxes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    Resolved [RESOLVED] SUM of Textboxes

    Code:
            
    Dim result As Integer
    Dim rc As Integer = CType(FormView1.FindControl("rental_chargeTextBox"), TextBox).Text
    Dim ssm1 As Integer = CType(FormView1.FindControl("SSMTextBox"), TextBox).Text
    Dim ssm2 As Integer = CType(FormView1.FindControl("SSM2TextBox"), TextBox).Text
    Dim ssm3 As Integer = CType(FormView1.FindControl("SSM3TextBox"), TextBox).Text
    result = Int(rc) + Int(ssm1) + Int(ssm2) + Int(ssm3)
    CType(FormView1.FindControl("total_rental_chargeTextBox"), TextBox).Text = result
    What i am trying to achieve is if:
    rc=10
    ssm1=1
    ssm2=0
    ssm3=1
    result would equal 12.
    What i am getting is 1011.

    Can anyone tell me why it is adding them together into a string instead of adding the textbox values together as a sum total?

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: SUM of Textboxes

    Try changing this line:
    Code:
    result = Int(rc) + Int(ssm1) + Int(ssm2) + Int(ssm3)
    To this:
    Code:
    result = CInt(rc) + CInt(ssm1) + CInt(ssm2) + CInt(ssm3)
    PS Turn Option Strict on! (it will help you avoid problems like this)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3
    Member
    Join Date
    Mar 2008
    Location
    East Kent, UK
    Posts
    34

    Re: SUM of Textboxes

    I would also suggest turning Option Strict On, as

    Code:
    Dim rc As Integer = CType(FormView1.FindControl("rental_chargeTextBox"), TextBox).Text
    is technically not a valid line.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width