Visual Basic Programming

Page 12

As you may recall on Page 9, Visual Basic can test values and return something depending on the result. Another form of this selection process is the Select Case structure. This allows the programmer to choose certain conditions depending on the value of a user input (text box, etc.) or of a variable. In this exercise, we will design a tax withholdings calculator as seen above to demonstrate this method.

Now to code the application:

The code above simply declares form-level variables named lngIncome and lngWithholding as the Long.

The lng prefix to Income is just an identifier to remind the programmer what type of variable they are using (in this case Long). We did not do that previously, but it is not necessary. Any serious programmer heavy into programming principles would debate that passionately, but I just want to try to teach you how to do it. I know plenty of people who do not care about most of the principals of programming. The principles will only become partially important when and if you decide to do this for a company. Now we will continue.

Now we will begin our Case statement.

This code will not tax anything equal to or below 4000 dollars. Refer to the comments to understand code if necessary.

This code multiplies the text in txtIncome by .04, then assigns the value to the variable lngWithholding.

Now to finish this program off. Just remember that the Case statement that sets the range determines the decimal, or percentage, that txtIncome.Text will be multiplied by.

Try testing the application now if you would like.

I hope you enjoyed this study in cases. Now it is time to move on to Page 13.

How do you like this tutorial? Are you learning this language easily? Please let me know via e-mail at webtechjava@yahoo.com.

Top of Page

Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Page 9 | Page 10 | Page 11

Page 12 | Page 13 | Page 14 | Page 15 | Page 16 | Page 17 | Page 18 | Page 19 | Page 20

Page 21 | Page 22 | Page 23 | Page 24 | Page 25 | Page 26 | Page 27 | Page 28 | Page 29 | Page 30