Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > adding up


Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2003, 09:30 PM
jessmas jessmas is offline
Centurion
 
Join Date: Dec 2002
Location: Hamilton, New Zealand
Posts: 166
Default adding up


I have the following code in my program. I am trying to get the total values into txtTotal. But it does not want to. Is the txtTotal_Click() correct??

It also needs to adjust itself as and when the user enters the figures.

Private Sub txtTotal_Click()

txtTotal.Text = Val(txtPlans.Text) + Val(txtPermit.Text) + _
Val(txtBuilder.Text) + Val(txtBench.Text) + _
Val(txtSand.Text) + Val(txtBobcat.Text) + _
Val(txtBlocks.Text) + Val(txtLayer.Text) + _
Val(txtRoof.Text) + Val(txtWindows.Text)

End Sub

Thanks in advance
Reply With Quote
  #2  
Old 05-16-2003, 09:54 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

Shouldn't there be a button to click on instead of trying to click on the text field?

Anyways, the other code seems ok to me if you have those text fields.
__________________
Avatar by the very talented member: lebb
Reply With Quote
  #3  
Old 05-16-2003, 09:58 PM
starbitz's Avatar
starbitz starbitz is offline
Junior Contributor
 
Join Date: Feb 2003
Location: Philippines
Posts: 336
Default

I suggest you put the above formula to a Sub and call this Sub to each textbox's Change Event. For Example:
Code:
Public Sub GetTotal() txtTotal.text = Val(txtPlans.Text) + Val(txtPermit.Text) + _ Val(txtBuilder.Text) + Val(txtBench.Text) + _ Val(txtSand.Text) + Val(txtBobcat.Text) + _ Val(txtBlocks.Text) + Val(txtLayer.Text) + _ Val(txtRoof.Text) + Val(txtWindows.Text) End Sub
Then in each textbox change event, call this Sub like:
Code:
Private Sub txtPlans_Change() GetTotal End Sub
...and so with other textboxes, except for txtTotal_change event So that its value will adjust to every entry modified.
__________________
"Everything should be made as simple as possible, but not simpler."
- Albert Einstein
Reply With Quote
  #4  
Old 05-16-2003, 10:04 PM
xXxRUxXx xXxRUxXx is offline
Regular
 
Join Date: May 2003
Posts: 78
Cool Try This

to save all this to Total.txt file i think this will work:


Code:
Dim txtTotal As Long txtTotal = FreeFile Open App.Path & "\Total.txt" For Output As #txtTotal Print #txtTotal, txtPlans.Text + " " + txtPermit.Text + " " + txtBuilder.Text + " " + txtBench.Text + " " + txtSand.Text + " " + txtBobcat.Text + " " + txtBlocks.Text + " " + txtLayer.Text + " " + txtRoof.Text + " " + txtWindows.Text Close #txtTotal


if it is not what you mean post and explain!
__________________
C:\> Format C:
Warning, All Data On NON-REMOVABLE Disk Drive C: will be Lost !
Proceed with Format <Y/N>? mmm !! let me Think...
Reply With Quote
  #5  
Old 05-16-2003, 10:07 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

xXxRUxXx: I don't think he needs to save the results to a file...just show the results in the textbox control.
__________________
Avatar by the very talented member: lebb
Reply With Quote
  #6  
Old 05-16-2003, 10:10 PM
xXxRUxXx xXxRUxXx is offline
Regular
 
Join Date: May 2003
Posts: 78
Default

ohh ok.... starbitz's method will work fine


VB:
--------------------------------------------------------------------------------
Public Sub GetTotal()
txtTotal.text = Val(txtPlans.Text) + Val(txtPermit.Text) + _
Val(txtBuilder.Text) + Val(txtBench.Text) + _
Val(txtSand.Text) + Val(txtBobcat.Text) + _
Val(txtBlocks.Text) + Val(txtLayer.Text) + _
Val(txtRoof.Text) + Val(txtWindows.Text)
End Sub
--------------------------------------------------------------------------------


Then in each textbox change event, call this Sub like:

VB:
--------------------------------------------------------------------------------
Private Sub txtPlans_Change()
GetTotal
End Sub
__________________
C:\> Format C:
Warning, All Data On NON-REMOVABLE Disk Drive C: will be Lost !
Proceed with Format <Y/N>? mmm !! let me Think...
Reply With Quote
  #7  
Old 05-16-2003, 10:13 PM
alp0001's Avatar
alp0001 alp0001 is offline
Xtreme Tester

Retired Moderator
* Expert *
 
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
Default

It all depends on what jessmas needs. It will take less coding to simply add a button (or menu) and throw all that addition code into it. But if the data should change on the fly without user interaction, then yes using the change event for EACH textbox will be needed.
__________________
Avatar by the very talented member: lebb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding a row in a MSHFlexGrid after I use removeitem jabrego General 19 03-17-2003 10:48 PM
adding unformated table to the msaccess VolodyAnarchist Word, PowerPoint, Outlook, and Other Office Products 2 02-19-2003 08:16 AM
adding records to database with unknown fields cyclonebri Database and Reporting 2 12-06-2002 10:11 AM
Adding a reference to Windows Media Player as bad as the control? Bucky General 0 02-21-2002 03:42 PM
Adding numbers JayNg General 1 11-27-2001 02:58 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->