 |
 |

05-16-2003, 09:30 PM
|
|
Centurion
|
|
Join Date: Dec 2002
Location: Hamilton, New Zealand
Posts: 166
|
|
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
|
|

05-16-2003, 09:54 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
|
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
|

05-16-2003, 09:58 PM
|
 |
Junior Contributor
|
|
Join Date: Feb 2003
Location: Philippines
Posts: 336
|
|
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
|

05-16-2003, 10:04 PM
|
|
Regular
|
|
Join Date: May 2003
Posts: 78
|
|
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...
|

05-16-2003, 10:07 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
|
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
|

05-16-2003, 10:10 PM
|
|
Regular
|
|
Join Date: May 2003
Posts: 78
|
|
|
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...
|

05-16-2003, 10:13 PM
|
 |
Xtreme Tester
Retired Moderator * Expert *
|
|
Join Date: Jan 2002
Location: Round Lake Heights, IL
Posts: 2,815
|
|
|
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
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|