By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 431,983 Members | 1,717 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,983 IT Pros & Developers. It's quick & easy.

# calculation for total sum

 P: 9 ive been working on this code for a long time... bt doesn't work... i want it to total up the sum of the number, there are adding and deletion of numbers, bt the sum doesn't appear rite... here's my screwed up code Expand|Select|Wrap|Line Numbers Private Sub Command7_Click() Text4.Text = Total End Sub Private Sub ctrlAddButton_Click() Total = 0       ctrlListBox1.AddItem ctrlTextBox1.Text     Total = ctrlTextBox1.Text + Total     If (ctrlDeleteButton.Enabled = False) Then       ctrlDeleteButton.Enabled = True       End If   End Sub Private Sub ctrlDeleteButton_Click()     If (Not (ctrlListBox1.ListCount = 0)) Then         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)         Total = ctrlTextBox1.Text - Total         If (ctrlListBox1.ListCount = 0) Then                 ctrlDeleteButton.Enabled = False         End If       End If End Sub Private Sub Form_Load()     If (ctrlListBox1.ListCount = 0) Then         ctrlDeleteButton.Enabled = False     End If End Sub Apr 30 '07 #1
Share this Question
3 Replies

 P: 9 this is after i modified, my total sum always appears as 0 Expand|Select|Wrap|Line Numbers Private Sub Command7_Click() Total = 0 If (ctrlAddButton) Then Total = CInt(ctrlTextBox1) + Total End If If (ctrlDeleteButton) Then Total = CInt(ctrlTextBox1) - Total End If Text4.Text = Total End Sub Private Sub ctrlAddButton_Click()     ctrlListBox1.AddItem ctrlTextBox1.Text   If (ctrlDeleteButton.Enabled = False) Then   ctrlDeleteButton.Enabled = True   End If   End Sub Private Sub ctrlDeleteButton_Click()     If (Not (ctrlListBox1.ListCount = 0)) Then         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)         If (ctrlListBox1.ListCount = 0) Then                 ctrlDeleteButton.Enabled = False         End If       End If End Sub Private Sub Form_Load()     If (ctrlListBox1.ListCount = 0) Then         ctrlDeleteButton.Enabled = False     End If End Sub Apr 30 '07 #2

 P: 9 this is my latest .... now when i delete, i delete the last inserted number , how to change it instead from deleting from the last inserted number, bt it deletes from the list? Expand|Select|Wrap|Line Numbers Private Sub Command7_Click() Text4.Text = Total End Sub Private Sub ctrlAddButton_Click()     ctrlListBox1.AddItem ctrlTextBox1.Text     If (ctrlDeleteButton.Enabled = False) Then         ctrlDeleteButton.Enabled = True     End If     If (ctrlAddButton) Then         Total = CInt(ctrlTextBox1) + Total     End If   End Sub Private Sub ctrlDeleteButton_Click()     If (Not (ctrlListBox1.ListCount = 0)) Then         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)         If (ctrlListBox1.ListCount = 0) Then                 ctrlDeleteButton.Enabled = False         End If         If (ctrlDeleteButton) Then         Total = Total - CInt(ctrlTextBox1)         End If     End If End Sub Private Sub Form_Load()     If (ctrlListBox1.ListCount = 0) Then         ctrlDeleteButton.Enabled = False     End If End Sub   Apr 30 '07 #3

 Expert 5K+ P: 8,434 ...how to change it instead from deleting from the last inserted number, bt it deletes from the list? Can you try to ask this question in a different way? I can't tell exactly what you mean. Expand|Select|Wrap|Line Numbers Private Sub Command7_Click()   Text4.Text = Total End Sub   Private Sub ctrlAddButton_Click()   ctrlListBox1.AddItem ctrlTextBox1.Text   If (ctrlDeleteButton.Enabled = False) Then     ctrlDeleteButton.Enabled = True   End If   If (ctrlAddButton) Then     Total = CInt(ctrlTextBox1) + Total   End If End Sub   Private Sub ctrlDeleteButton_Click()   If (Not (ctrlListBox1.ListCount = 0)) Then     ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)     If (ctrlListBox1.ListCount = 0) Then       ctrlDeleteButton.Enabled = False     End If     If (ctrlDeleteButton) Then       Total = Total - CInt(ctrlTextBox1)     End If   End If End Sub   Private Sub Form_Load()   If (ctrlListBox1.ListCount = 0) Then     ctrlDeleteButton.Enabled = False   End If End Sub Two questions:Where Is the variable Total defined? What is the purpose of testing If CtrlDeleteButton (see highlighted line in code)? If this is supposed to test whether the delete button was clicked, you already know that because you're in the click handler routine. Hm... I suppose the same applies to testing If (ctrlAddButton), further back. Apr 30 '07 #4

### Post your reply

Sign in to post your reply or Sign up for a free account.