Visual Basic Programming

Page 6

I will get the simple stuff done with first, then the more difficult code. No worry though! I will try to explain the code line-by-line as before. The code involved is incredibly simple, but only because I know how. Lets begin.

You may have guessed that the End command will go into the Exit button on the form. Duh!

Now lets code the Clear command button.

Just as the code says, the text and caption properties for the specified objects will be empty when cmdClear is clicked.

This line converts the text in the text box txtState to uppercase characters using the UCase function when the cursor leaves the text box.

Now it is time to finally calculate this order form.

Note: We will use a function called Val, which treats a string as a numeric value. Otherwise, the program will concatenate the string, or put them together. For instance: 2 + 12 will equal 212 if we enter it into code like it is. A string is simply text, nothing more. Anyway,

The code above simply states that the caption in lblTotal will equal the value of txtSheetrock.Text plus the value of txtBlueboard.Text. Test the application if you want. Make sure you only enter numbers. The Val statement only looks at numbers in a string. If you enter letters in the text boxes, it will return, or display 0.

Examples:

Val("105 Riders Lane") returns 105

Val("Riders Lane") returns 0


Now lets display some total value.

The code above simply states that the total price label caption will equal the price entered into txtSheetrockPrice.Text, times the quantity entered into txtSheetrock.Text, plus the price entered into txtBlueboardPrice.Text, times the quantity entered into txtBlueboard.Text.

Sounds wordy huh? You're right! There is no other way to explain it though.

I hope it worked for you, because now we will change something else! Notice how the total price is not calculated in a dollar and cents format. To change this, we will use a function called Format.

This code tells the computer to format the label lblTotalPrice in dollars and cents format in the thousands. You can also replace the "$0,0.00" with "Currency" and it will format the same way.

Tip: Remember to make sure that you place your parenthesis in the proper places for more complex computations

Example

Val(txtText.Text) * Val(txtText2.Text) * 5 will return something different than (Val(txtText.Text) * Val(txtText2.Text)) *5.
(Val(txtText.Text) * Val(txtText2.Text)) * 5 multiplies the product of both text values by 5.
Val(txtText.Text) * Val(txtText2.Text) * 5 solely multiplies txtText2.text by 5 and multiplies that product by txtText.text.

We will deal with printing in later point in this tutorial.

Keep trying these examples and experiment with other text controls IF you are lost. Otherwise, move on to Page 7.

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

Back to Top

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