DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   (calc) Subtraction code with VB6 (http://www.daniweb.com/forums/thread157678.html)

BigSeckC Nov 16th, 2008 9:25 am
(calc) Subtraction code with VB6
 
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 :D

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! :D


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!



'setting up Integers for
'calculations

Option Explicit
    Dim intgsal As Integer  'Gross Salary
    Dim intnet As Integer    'Net Salary
    Dim inthrs As Integer    'Hours Worked
    Dim intded As Integer    'Deductions

'setting text box values to
'"blank" and "0"

Private Sub Form_Load()
    txtname.Text = " "
    txthrs.Text = "0.00"
    txtded.Text = "0.00"
    txtgsal.Text = "0.00"
    txtnet.Text = "0.00"

End Sub

'coding Confirm to calculate

Private Sub cmdconfirm_Click()

If opta.Value = True Then _
    intgsal = (txthrs.Text * 10)
     
txtgsal.Text = intgsal

End Sub

BigSeckC Nov 16th, 2008 10:14 am
Re: (calc) Subtraction code with VB6
 
Got it!!! Figured out the Code I needed... at least for now...

'coding Confirm to calculate

Private Sub cmdconfirm_Click()

If opta.Value = True Then
    intgsal = (txthrs.Text * 10)
      txtgsal.Text = intgsal
    intnet = (intgsal - txtded.Text)
        txtnet.Text = intnet
End If
End Sub


All times are GMT -4. The time now is 3:59 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC