sub total

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pennpaul
    New Member
    • Oct 2009
    • 4

    sub total

    i need to be able get the subtotals of specific textbox data

    how can i say get textbox1 and textbox2 data to add up , or any variance as the user wishes . i have this so far
    .
    Code:
    Function Total(ByVal ddeptprofit() As Double, ByVal ndept As Integer)
            
            Dim dtotal = 0
            Dim i As Integer
            For i = 0 To ndept - 1
               
                ddeptprofit(0) = CDbl(TextBox1.Text)
                dtotal = dtotal + ddeptprofit(i)
            Next
            Return dtotal
        End Function  
       
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            
            Dim ndept = 5
            Dim ddeptprofit(ndept) As Double
            ddeptprofit(0) = CDbl(TextBox1.Text)
                          
            ddeptprofit(1) = CDbl(TextBox2.Text)
            ddeptprofit(2) = CDbl(TextBox3.Text)
            ddeptprofit(3) = CDbl(TextBox4.Text)
            ddeptprofit(4) = CDbl(TextBox5.Text)
            
            Dim dtotalprofit As Double
            dtotalprofit = Total(ddeptprofit, ndept)
            
            Label1.Text = "total is" & dtotalprofit.ToString
    Last edited by Frinavale; Nov 23 '09, 05:40 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    I don't understand something.
    You have declared an array of Doubles in your Button1_Click method.

    Then you go through all of the TextBoxes, retrieve the values entered by the user, cast them in to Doubles, and then add them to the array of Doubles.

    Then you are passing the array of Doubles into the Total method...and for some reason you are setting the first element of this array to the value in TextBox1 while looping through the array.

    Code:
    Function Total(ByVal ddeptprofit() As Double, ByVal ndept As Integer)
     
            Dim dtotal = 0
            Dim i As Integer
            For i = 0 To ndept - 1
     
                ddeptprofit(0) = CDbl(TextBox1.Text)'<--???
                dtotal = dtotal + ddeptprofit(i)
            Next
            Return dtotal
    End Function
    I find this weird but I don't see any reason why this code wouldn't produce the total.

    What is the problem?

    -Frinny

    Comment

    • pennpaul
      New Member
      • Oct 2009
      • 4

      #3
      the problem is i cant get the totals of various text boxs. say i want the subtotal of txtb3 and txtb5 , i think i need to input that i specifically need the subtotal of only these text box's. but i dont know how to . Sorry if their are errors i am still learning . I get the total of all of them, but dont know how to gather variations .

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Have you considered placing CheckBoxes next to each TextBox?
        Let the user check which TextBoxes they want the total for. Loop through the CheckBoxes to determine which ones were selected and create the sub total for the selected TextBoxes.

        -Frinny

        Comment

        • pennpaul
          New Member
          • Oct 2009
          • 4

          #5
          how could i do that? the only chckboxs i have used have been in a case select.

          Comment

          Working...