help with a program

hey just started using vb about a week ago. well i'm writing this program to find out a salary after tax is taken out using if commands. Here's what i have so far

Private Sub Command1_Click()
Dim salary, netpay, taxes As Single
Text1.Text = salary
Text2.Text = netpay

If salary >= 0 And salary <= 8025 Then
taxes = Val(Text1.Text) * 0.1
Text2.Text = Str(netpay)
End If


If salary >= 8026 And salary <= 32550 Then
taxes = Val(Text1.Text) * 0.15
netpay = salary - taxes
Text2.Text = Str(netpay)
End If

If salary >= 32551 And salary <= 78850 Then
taxes = Val(Text1.Text) * 0.25
netpay = salary - taxes
Text2.Text = Str(netpay)
End If

If salary >= 78851 And salary <= 164550 Then
taxes = Val(Text1.Text) * 0.28
netpay = salary - taxes
Text2.Text = Str(netpay)
End If

If salary >= 164550 And salary <= 357700 Then
taxes = Val(Text1.Text) * 0.33
netpay = salary - taxes
Text2.Text = Str(netpay)
End If

If salary >= 357701 And salary <= 1E+17 Then
taxes = Val(Text1.Text) * 0.35
netpay = salary - taxes
Text2.Text = Str(netpay)
End If


End Sub

I can't figure out what's wrong cause the netpay keeps coming out as zero. Any help is appreciated

Comments

  • : hey just started using vb about a week ago. well i'm writing this
    : program to find out a salary after tax is taken out using if
    : commands. Here's what i have so far
    :

    I haven't looked through the entire code for errors, but the following (in red) is what's causing your problems:

    [code]
    : Private Sub Command1_Click()
    : Dim salary, netpay, taxes As Single
    : [color=Red]Text1.Text = salary
    : Text2.Text = netpay[/color]
    : ...
    [/code]
    The assignments should be reversed -> salary = Text1.Text and not the other way :P

    Also, I'd like to note that
    [code]Dim salary, netpay, taxes As Single[/code]
    does not do what you'd expect it to. In fact, taxes is the only variable defined as a Single by this line. salary and netpay will be Variants. It's a VB quirk, and you won't find it in other languages, but the correct definition is:
    [code]Dim salary As Single, netpay As Single, taxes As Single[/code]


    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion