Saturday, January 22, 2011

VB.NET Tutorial #4

The Checked and Me Keyword


Object used: RadioButtons , Button and GroupBoxes
Simple Multi-Operation Program
Consider this program.





How this program works?
First the user must input two numbers in the two textboxes (txtn1 & txtn2). Next is the user must choose one one of the operators specified to the radiobuttons. If the user choose the "Addition" RadioButton (rbAddition) and click the "Compute" Button, the program will compute the sum of the numbers inputted in the textboxes and display it to the "Answer" TextBox (txtanswer). The same goes with the other operators. Compute then display the answer to the third textbox.

Checked Keyword is use to check the radiobutton.
For Example,

If(RadioButton1.checked=True){
     // Do a certain command here:
     TextBox1.Text = "Hello There! "
}


In the given example, IF the RadioButton1 is "checked" or choose by the user (true), a text to the TextBox1 will appear.

Me Keyword is use to specify which object you are referring for.
For Example,

Me.TextBox1.Text = "Hello There! "


Me is used to refer that the "TextBox1" he (programmer) is referring for is the TextBox1 in the current form.
There maybe TextBox1 exist in the other controls or form.
Me keyword is equivalent to this keyword of Java.

The Program Codes
For Button "Compute"
First declare the variable for the two numbers and the possible outcome (answer). Initialize that the value of the first number (inputted in the txtn1) is a Double value. The same as the second number. Create a Conditional Operation "IF-ELSEIF", decide what IF the user choose the first radiobutton (rbAdd for Addition), the program will get the two numbers inputted in the textboxes and do the basic addition operation for those two numbers, then display the answer to the "txtanswer" TextBox.


Form Load Event
This will initialize the editable of the txtanswer.


◄ Newer Post Older Post ►
 

Copyright 2012 | Credits: BLog BamZ (For the template)