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.


Monday, December 27, 2010

VB.NET Tutorial #3

The .Visible and .Enabled Keyword


Object Used:  Button and TextBox
Simple Buttons Program
Consider this Program






How this program works?
When I click the "Disabled TextBox And Button", the TextBox and the Button (located at the top of the program) will be disabled (Meaning you can't edit it anymore). But when I click the "Enabled TextBox And Button", Both of them will be enable (E. You can now edit it.). 
When I click the "Hide TextBox And Button", both of the object above will be hide. But when I click "Show TextBox And Button", It will appear to the program again.

The Program Codes



Sunday, December 26, 2010

VB.NET Tutorial #2

The .Clear and CDbl Keyword

Object Used: Button, TextBox and Label 
Simple Addition and Subtraction Program
Consider this Program.
























How this Program Works?
When I enter a value of the addends (txtn1 and txtn2) and the value of the subtrahend & minuend (txtn3 and txtn4), the program will compute for the sum and difference. When I click the button "Operate", the answers will be displayed on the txtsum and txtdiff.  When I click the button "Clear", All of the contents of the textboxes will be cleared.

CDbl keyword (Meaning Convert to Double) is used to set the data type of a variable to Double. For Example,

Some_Value = CDbl(TextBox1.Text)


Meaning that the variable "Some_Value" is set to a Double Value. It specify that the variable (whose value is at the TextBox1) is a Decimal Value.

.Clear keyword is used to clear the whole content of the object (usually a Textbox). For Example,

TextBox1.Clear( )

This will clear the content of the TextBox1.

The Program Codes:
For Button Operate.


First, declare all variables to be used. I have to declare them as double and set those values to a Double Value. I set a formula that will add and subtract the double values (entered to txtn1 and so on) and display the  answer to another textbox.

For Clear Button


This command will clear the content of the textboxes.


VB.NET Tutorial #1


The .Text and CStr Keyword 

Object Used: TextBox, Label and Button and MessageBox
Simple Hello World Program
Consider this Program



How this Program works?
When the User enter the required field in the TextBox (To be specific "Name") and clik the Greet Button, a MessageBox will pop-up and it will display the word "Hello" combining the word/text you typed in the TextBox.



Exposition:
.Text Keyword is used to initiate/specify that the content of the TextBox is a bunch of text. You usually see it paired with the textbox as it's object. For Example,

TextBox1.Text = Some_Value


Meaning that the content of the variable "Some_Value" will be display to the TextBox1. .Text specify that the variable's content (that will be placed at the TextBox1) is a text or a character.


      CStr Keyword (Meaning Convert to String) is used to initiate/set the data type of the variable to a String. For Example,


Some_String = CStr(TextBox1.Text)


Meaning anything you type to the TextBox1 will be set to a String. Anything you type to TextBox1 will be considered as a String.

The Program Codes. Just Double Click the Button "Greet" and start typing this code.


First, I have to declare a variable and I need to set its data type to string (because MyName will not be containing any numbers or whatever). After declaring the variable, Set the variable's data type to a String and the name of  the textbox in which the variable's value is stored. In this case, I will type MyName 's Value to a Textbox with a name of "txtname".  In the screenshot above, I typed "Mr. Fledgling" at the TextBox named "txtname". Then I call out the presence of the MessageBox in my program and write "Hello " plus the string named "MyName".

Introductory Topics before you start writing VB.Net Codes

Variable's Declaration
In VB.Net, you must declare the variables and its data type.
The general equation is:

Dim var As Type
Where "var" is a variable and "Type" is a valid DataType.

OR


Dim var1, var2 As Type
If you have more than one variable to be declared. Be sure that var1 and var2 has a common DataType.

VB.Net Variable's DataTypes
A. Double - Use to specify that the variable is a Decimal Value.
Ex.
Dim var1 As Double = 3.145; or 
Dim var1 As Double


B. Int - Use to specify that the variable is an Integer Value.
Ex.
Dim var1 As Int 

C. String - Use to specify that the variable is a group of characters.
Ex.
Dim name As String


D. Char - Use to specify that the variable is a character.
Ex.
Dim gender As Char

Visual Basic .NET GUI Programming

Some of Common Controls/Objects we will be using are:

ComboBox - is a drop down list object. It list the items with the style of dropping down.
ListBox - is like a "not a drop down style" of the ComboBox. It will list items without the style of dropping down.
Label - It is use to wite text directly on the form/interface. It is often use for instruction or notes for the program.
TextBox - It is use to fill different text/information. You can type text inside it. 
GroupBox - It is use to group objects in a specific location.
Button - It is use to hold a specific instruction or command.
CheckBox - It is use to hold an option. You can select multiple choices/options. 
RadioButton - It is use to hold an option. You can select one choice at a time.
Progressbar - It serves as a timer for your program. 
ToolStripMenu - It use to group a variety of commands

Illustration:








Getting Started with Microsoft Visual Studio

FAQ:
Q. How to create a new Console Application?
A. Open MS Visual Basic Express Edition.

Click "File", Choose "New Project". In the Dialog Box, click "Console Application", type the project's name, then click OK.

Q. How to create a new Windows Form Application
A. Click on the "File", Choose "New Project". In the Dialog Box, click "Windows Form Application", type the project's name, then click OK.

Q. What is the difference between Windows Form App. and Console App.?

        Console Application                                    Windows Form Application
1. It will only run on the Command Prompt.      1.  It has their own interfaces.(GUI)
2. AKA "Command Line Programming"              2. AKA "Object Oriented Programming"
-It only uses variables and some instruction          -It uses some objects ..
  to run.
3. NOT a Event Driven                                             3. It is a Even Driven.
4. It only accepts KeyBoard command.               4. It accepts command from both of the                                                                                            keyboard and mouse.
5. "Enter" is only acceptable.                     5. There are a lot of events that is acceptable.
                                                          
 

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