Help - Search - Members - Calendar
Full Version: vb.net bring home pay
ieXbeta Board > Tech > Developer Center
Chan1975
I have the following code in vb.net lang to calucate bring home pay. When I enter the income it just displays the same number in then answer box. Anyone help?

CODE
Dim pay As String
       pay = incomebx.Text
       Dim taxpr As Double

       If btnsingle.Checked = True Then
           If pay = 0 <= 102 Then
               taxpr = 0
           ElseIf pay = 103 <= 373 Then
               taxpr = 0.1
           ElseIf pay = 374 <= 1185 Then
               taxpr = 0.15
           ElseIf pay = 1186 <= 2635 Then
               taxpr = 0.25
           ElseIf pay = 2636 <= 5719 Then
               taxpr = 0.28
           ElseIf pay = 5720 <= 12354 Then
               taxpr = 0.33
           Else
               taxpr = 0.35

           End If
       Else
           If pay = 0 <= 308 Then
               taxpr = 0
           ElseIf pay = 309 <= 858 Then
               taxpr = 0.1
           ElseIf pay = 859 <= 2490 Then
               taxpr = 0.15
           ElseIf pay = 2491 <= 4540 Then
               taxpr = 0.25
           ElseIf pay = 4541 <= 7137 Then
               taxpr = 0.28
           ElseIf pay = 7138 <= 12542 Then
               taxpr = 0.33
           Else
               taxpr = 0.35

           End If

       End If

       ' Declare double for tax withheld and cal. tax
       Dim taxs As Double
       taxs = pay * taxpr

       'Cal bring home pay and display
       takepay.Text = pay + taxs


   End Sub
Ludo
Have you tried the debugger? Going step by step through your code ?

And are you sure of the syntax of
CODE
ElseIf pay = 103 <= 373 Then


Shoudn't it be something like
CODE
ElseIf pay >= 103 And Pay <= 373 Then


?

edited to clarify code
quantumAlpha
umm, correct me if im wrong, but i think your conditional syntax is wayy off.

I would write
CODE
ElseIf pay = 103 <= 373 Then

as
CODE
ElseIf pay>=103 and pay<=373 Then

Use the AND to signify that you have a compund conditional

Edit: well, it looks like Ludo beat me to it
Ludo
smile.gif
vbjay
If I am doing a lot of elseifs I use a select case instead


CODE

If btnsingle.Checked = True Then
           Select Case pay  
                 case <= 102
               taxpr = 0
           Case <= 373
               taxpr = 0.1
           Case  <= 1185
               taxpr = 0.15
           Case <= 2635
               taxpr = 0.25
           case <= 5719
               taxpr = 0.28
           case <= 12354
               taxpr = 0.33
           case Else
               taxpr = 0.35

           End Select.......


This code will work because the cases are in order.

Say pay is 200 it will go to the case <=373 line and then exit the Select part and go on with the rest of the code.
quantumAlpha
yeah, good point, but was it good enough to revive a 2 year old post?
vbjay
QUOTE(quantumAlpha @ Jul 5 2006, 10:20) *

yeah, good point, but was it good enough to revive a 2 year old post?

Sorry. I was looking for a way to tile a listview in vb.net and saw a post on that subject on this board. This post was the post near the post I was interested in. I did not pay attention to the post date. I just thought I would post a tip for readability.
DangerousDave86
This forum doesn't get that much usage round here. Do you know any good n00b friendly forums we could direct people to for help... and that I could possibly use in future for my dumb VB questions, lol.
vbjay
I have posted a LOT at GotDotNet
See my profile there.

GotDotNet

GotDotNet Newbies message board

I used to do VBCity.

MSDN

DangerousDave86
Cheers vbjay
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.