943,771 Members | Top Members by Rank

Ad:
Nov 16th, 2008
0

(calc) Subtraction code with VB6

Expand Post »
Hey all,

I apologize now for being a Noob. I'm using a Tutorial to learn VB6 (for starters) and everything was going great until just now... The assignment is to create a Weekly Payroll. I have managed to figure out how to make the standard calc ( Hrs worked * Rate ) and display properly, however, that's when my legs get knocked out from under me

I'm not entirely sure how to subtract the deductions. I tried searching but couldn't find a similar situation. Below is my working code, albeit probably OC'd... over-coded.

*scratches head... how do I subtract? I 'thought' it would be:

If opta.Value = True Then _
intgsal = (txthrs.Text * 10) _
And intnet = (txthrs.Text * 10 - txtded.Text) <-- txtded.Text being my Deductions

txtgsal.Text = intgsal
txtnet.Text = intnet

...I was sooooo wrong... more errors than a little bit!


My 'working' code is below - any help would be appreciated! Also, if there are shortcuts (i.e., functions) that I could use in the future - I would like to know that as well!

Thanks again!



vb Syntax (Toggle Plain Text)
  1. 'setting up Integers for
  2. 'calculations
  3.  
  4. Option Explicit
  5. Dim intgsal As Integer 'Gross Salary
  6. Dim intnet As Integer 'Net Salary
  7. Dim inthrs As Integer 'Hours Worked
  8. Dim intded As Integer 'Deductions
  9.  
  10. 'setting text box values to
  11. '"blank" and "0"
  12.  
  13. Private Sub Form_Load()
  14. txtname.Text = " "
  15. txthrs.Text = "0.00"
  16. txtded.Text = "0.00"
  17. txtgsal.Text = "0.00"
  18. txtnet.Text = "0.00"
  19.  
  20. End Sub
  21.  
  22. 'coding Confirm to calculate
  23.  
  24. Private Sub cmdconfirm_Click()
  25.  
  26. If opta.Value = True Then _
  27. intgsal = (txthrs.Text * 10)
  28.  
  29. txtgsal.Text = intgsal
  30.  
  31. End Sub
Reputation Points: 12
Solved Threads: 0
Newbie Poster
BigSeckC is offline Offline
13 posts
since Nov 2008
Nov 16th, 2008
0

Re: (calc) Subtraction code with VB6

Got it!!! Figured out the Code I needed... at least for now...

vb Syntax (Toggle Plain Text)
  1. 'coding Confirm to calculate
  2.  
  3. Private Sub cmdconfirm_Click()
  4.  
  5. If opta.Value = True Then
  6. intgsal = (txthrs.Text * 10)
  7. txtgsal.Text = intgsal
  8. intnet = (intgsal - txtded.Text)
  9. txtnet.Text = intnet
  10. End If
  11. End Sub
Reputation Points: 12
Solved Threads: 0
Newbie Poster
BigSeckC is offline Offline
13 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Macro Excel and serial port
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Remove the "x" in the window at runtime





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC