473,809 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calculation for total sum

9 New Member
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
  1. Private Sub Command7_Click()
  2. Text4.Text = Total
  3. End Sub
  4. Private Sub ctrlAddButton_Click()
  5. Total = 0
  6.  
  7.     ctrlListBox1.AddItem ctrlTextBox1.Text
  8.     Total = ctrlTextBox1.Text + Total
  9.     If (ctrlDeleteButton.Enabled = False) Then
  10.       ctrlDeleteButton.Enabled = True
  11.  
  12.     End If
  13.  
  14. End Sub
  15. Private Sub ctrlDeleteButton_Click()
  16.     If (Not (ctrlListBox1.ListCount = 0)) Then
  17.         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)
  18.         Total = ctrlTextBox1.Text - Total
  19.         If (ctrlListBox1.ListCount = 0) Then
  20.                 ctrlDeleteButton.Enabled = False
  21.         End If
  22.  
  23.     End If
  24. End Sub
  25. Private Sub Form_Load()
  26.     If (ctrlListBox1.ListCount = 0) Then
  27.         ctrlDeleteButton.Enabled = False
  28.     End If
  29. End Sub
Apr 30 '07 #1
3 1811
dreamonzzz
9 New Member
this is after i modified, my total sum always appears as 0

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command7_Click()
  2. Total = 0
  3. If (ctrlAddButton) Then
  4. Total = CInt(ctrlTextBox1) + Total
  5. End If
  6. If (ctrlDeleteButton) Then
  7. Total = CInt(ctrlTextBox1) - Total
  8. End If
  9. Text4.Text = Total
  10. End Sub
  11. Private Sub ctrlAddButton_Click()
  12.  
  13.   ctrlListBox1.AddItem ctrlTextBox1.Text
  14.   If (ctrlDeleteButton.Enabled = False) Then
  15.   ctrlDeleteButton.Enabled = True
  16.   End If
  17.  
  18. End Sub
  19. Private Sub ctrlDeleteButton_Click()
  20.     If (Not (ctrlListBox1.ListCount = 0)) Then
  21.         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)
  22.         If (ctrlListBox1.ListCount = 0) Then
  23.                 ctrlDeleteButton.Enabled = False
  24.         End If
  25.  
  26.     End If
  27. End Sub
  28. Private Sub Form_Load()
  29.     If (ctrlListBox1.ListCount = 0) Then
  30.         ctrlDeleteButton.Enabled = False
  31.     End If
  32. End Sub
Apr 30 '07 #2
dreamonzzz
9 New Member
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
  1. Private Sub Command7_Click()
  2. Text4.Text = Total
  3. End Sub
  4. Private Sub ctrlAddButton_Click()
  5.  
  6.   ctrlListBox1.AddItem ctrlTextBox1.Text
  7.     If (ctrlDeleteButton.Enabled = False) Then
  8.         ctrlDeleteButton.Enabled = True
  9.     End If
  10.     If (ctrlAddButton) Then
  11.         Total = CInt(ctrlTextBox1) + Total
  12.     End If
  13.  
  14. End Sub
  15. Private Sub ctrlDeleteButton_Click()
  16.     If (Not (ctrlListBox1.ListCount = 0)) Then
  17.         ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)
  18.         If (ctrlListBox1.ListCount = 0) Then
  19.                 ctrlDeleteButton.Enabled = False
  20.         End If
  21.         If (ctrlDeleteButton) Then
  22.         Total = Total - CInt(ctrlTextBox1)
  23.         End If
  24.     End If
  25. End Sub
  26. Private Sub Form_Load()
  27.     If (ctrlListBox1.ListCount = 0) Then
  28.         ctrlDeleteButton.Enabled = False
  29.     End If
  30. End Sub
  31.  
Apr 30 '07 #3
Killer42
8,435 Recognized Expert Expert
...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
  1. Private Sub Command7_Click()
  2.   Text4.Text = Total
  3. End Sub
  4.  
  5. Private Sub ctrlAddButton_Click()
  6.   ctrlListBox1.AddItem ctrlTextBox1.Text
  7.   If (ctrlDeleteButton.Enabled = False) Then
  8.     ctrlDeleteButton.Enabled = True
  9.   End If
  10.   If (ctrlAddButton) Then
  11.     Total = CInt(ctrlTextBox1) + Total
  12.   End If
  13. End Sub
  14.  
  15. Private Sub ctrlDeleteButton_Click()
  16.   If (Not (ctrlListBox1.ListCount = 0)) Then
  17.     ctrlListBox1.RemoveItem (ctrlListBox1.ListCount - 1)
  18.     If (ctrlListBox1.ListCount = 0) Then
  19.       ctrlDeleteButton.Enabled = False
  20.     End If
  21.     If (ctrlDeleteButton) Then
  22.       Total = Total - CInt(ctrlTextBox1)
  23.     End If
  24.   End If
  25. End Sub
  26.  
  27. Private Sub Form_Load()
  28.   If (ctrlListBox1.ListCount = 0) Then
  29.     ctrlDeleteButton.Enabled = False
  30.   End If
  31. End Sub
Two questions:
  1. Where Is the variable Total defined?
  2. What is the purpose of testing If CtrlDeleteButto n (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

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

Similar topics

2
2474
by: DebbieG | last post by:
I have no idea how to start with this one. I have a subform where records could look similar to: Infraction Date Points 01/01/2000 3 06/01/2002 1 Somehow, I've got to calculate the points the driver has as of the current date. For instance, in the above example:
1
2239
by: sgmarty | last post by:
Hi, I have an interesting problem. Without using reduncant data, how can I design a calculation field to get a running total from values in different records? I'm designing a usage/month report, and I'm confused. Date Value Calculation Record1: 08/05/06 12345 Record2: 09/05/06 23456 (23456-12345) Record3: 10/05/06 34567 (34567-23456) Thanks for the help. Steve
1
2285
by: erick-flores | last post by:
Hello all I have a linked table using ODBC. When I tried to do Count() and Sum() for this linked table (onw of the field in the table is name "total") the form takes forever to gives me the results, like 4 minutes. I am putting a textbox in the footer of my form to get this results. The table has around 1300 records. Is there a better way to get quicker results? I know I can copy the linked table to my local computer and then the
10
1701
by: hacorbin | last post by:
I have a VB.NET program I am creating that sums 7 textboxes and displays their total in a total textbox. code: Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click total.text = (Convert.ToInt32(rt1.Text) + Convert.ToInt32(rt2.Text) + Convert.ToInt32(rt3.Text) + Convert.ToInt32(rt4.Text) + Convert.ToInt32(rt5.Text) + Convert.ToInt32(rt6.Text) + Convert.ToInt32(rt7.Text)) What I want...
3
1950
by: ncsuwolfe | last post by:
Greetings, I am creating a frequency report. I have 41 records, each record has sub-records from a source table. I am trying to detemine the frequency that each sub-record appears in a main record. So, if a sub-record appears 5 times, the formula would be 5/41=0.12. The frequency calculation I currently have is residing in the footer of a report listed by sub-record. The footer displays sub-record name, total observations, and the...
3
1291
by: xwings | last post by:
I'm using Access as my database, and i have a table like this; Schedule Inseam Size Total ---------------------------------------------------------- 12100 30 32 10 12100 30 32 9 13100 32 38 7 14100 34 38 8 And i wan my table do the calculation like this;
0
1383
parshupooja
by: parshupooja | last post by:
Hi all, I need help. I am using asp.net C# . I have binded gridview with 5 columns. I have Dropdownlist in 4 columns Morning in, morning out, afternoon in and afternoon out and label in 5 column named as totalwhere i want to show calculation(morningout-morningin+afternoonout-afternoonin) but whenever i try to run this i get error in bolded section that "input string is not in correct format". However I have acheived this calculation on...
5
17443
kcdoell
by: kcdoell | last post by:
Hello: I thought I was done with this one but a user who is testing my DB just pointed out a problem. I used the following in the afterupdate event: Private Sub Binding_Percentage_AfterUpdate() 'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP 'on the quick reference table on the Forecast form.
22
2907
by: azura | last post by:
dear sir..my friend give me one code how to calculate without pressing any button... but i didn't know how to insert function to make it work... very very newbie in calculation using javascript..please someonehelp me please.. var total = (document.getElementById("cam").value + document.getElementById("final_exam").value) / 2; document.getElementById("total").value = total;
12
2566
by: brossyg | last post by:
I have a very simple price times quantity calculation. The input is STWCORQuant: <input name="STWCORQuant" class="contactitalicbold" id="STWCORQuant" onChange="javascript:STWCORPrice();" value="0" size="8" style="text-align: right; font-family: ver"> And the fucntion is STWCORPrice(): <script language="javascript" type="text/javascript">
0
9602
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.