Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

2nd Quarter

Introduction to Basic.NET Programming in Visual Basic.NET


Visual Basic 2008 is a development tool that you can use to build software applications that perform useful work and look great within a
variety of settings. You can create applications for the Windows operating system, the Web, hand-held devices, and a host of other
environments and settings.
Visual Basic 2008

Start Page contains a set of links, MSDN articles and Project Options. A comprehensive source of information about your project, as well as
resources within the Visual Basic development community
Toolbox
Contains controls and other component that can be placed on the form designer.
Solution Explorer Window
Provides you with a way to navigate through your program's structure, with entries for each form, module, and class, along with supporting files
such as the application configuration file.

Error/Task List Window


Will be populated with any potential issues with the code and form design of your application. Issues can be compiling or runtime errors that
need to be address.

Properties Window
Describes the properties or characteristics of the form and other controls.

Writing Windows Applications with VB


 Windows Graphical User Interface
 Window = Form
 Toolbox of elements called Controls
- Text Box
- Label
- Check Box
- Button

Using “ “ to create a space


Using + to join words
Object Model
Object - Noun
- Form and Controls
Property - Adjective
- Color of a Form
- Size of Text
Method - verb
- Move a form
Event – Occurs when the user takes action
- Use clicks a button, User moves a form
Class - Template to create new object
- Each control added is an instance of a class

Object Model Analogy


 Class – automobile
 Properties – make, model, color, year
 Object – each individual car
o Object is an Instance of the automobile class
 Methods – start, stop, speedup, slowdown
 Events – car arrives, car crashes, car is purchased

Performing calculations
 Operators:
o + is addition
o – is subtraction
o * MOD gets remainder
o / is *floating point division
o \ is *integer division
o *^ is exponentiation
 Examples:
Integers = 5 + 5
Integers = 5 MOD 5
{remainder shows)
Integer = 5 / 5
The following are symbols for declaring specific operations
Mathematical Operation Operator or Symbol Mathematical Notation Example Result
Addition + a+b 17+2 19
Subtraction - a-b 2-17 -15
Multiplication * a*b 2*17 34
Division / a/b 17/1 17
Exponentiation ^ a^b 7^2 49
+ or & String Concatenations String 1 + String2 or "Hello" + "World" Hello World
String1 & String2
mod Reminder of division a mod b 19mod3 1

RELATIONAL OPERATORS
Operators Description Mathematical Notation Example Result
> Greater than a>b 25>2 True
< Less than a<b 25<5 False
>= Greater than or equal to a>=b 83>-75 True
<= Less than or equal to a<=b 83<-75 False
<> Not equal a<>b Password <> computer True
= Equal a=b Password = computer False

The following are symbols for declaring specific operations


 Visual Basic follow the precedence of the formula like in Math wherein if follow the rules of EMDAS.
 Use parenthesis to alter the precedence followed by EMDAS. Expressions inserted inside a parenthesis will be executed first before the
other expressions.
Coding Part 5: If...Then and If...Else...Then Statements
Both statements are conditional statements
 Visual Basic is unique on this
 If... Then is one condition is met
 If... Else... Then is if one condition is not met then another event will trigger

LOGICAL OPERATORS
Operators Description Example Result
OR It will retrieve true value if the (25>3) OR (3<5) True
operand are true.
AND It will retrieve true value only (25>3) AND (3<5) True
if both operands are true
XOR Both must not be true meaning (25>3) XOR (3<5) False
only one side should hold true
value
NOT Reverse true side NOT (2=2) False

KINDS OF DATA TYPES


1. Numeric — a data type that holds whole numbers.
Two Category
a. Integers — which are whole numbers and without decimal.
b. Decimal — holds numbers with decimal points that usually represent fractional values like 3.1426, -22, etc.

2. Nonnumeric — usually consists of characters, date, Boolean data or variant data types.
Example:
a) String — is a series of characters which may range from zero or more characters. It may hold numeric characters but it is never used
for calculations.
b) Date — used for dates.
c) Boolean data — only holds two value or no, true or false.
d) Variant — data that cam holding any kinds of data except for fixed length strings.
EXPLICIT Declarations
It is advisable to declare all variables before they are used in a program.
Using the DIM statement to declare variables by assigning them a name and a data type. Below is the format of the DIN'I statement in a variable
declaration.
Dim Varname as Data Type
Varname is the name you assign to a variable and the
Data type is the type of data that the variable will hold.

EXPLICIT Declarations
Like giving names in a control, variables also used prefixes in assigning names to them. Below are the variable name prefixes that describe
variables data type.

Prefix Data Type Example


bln Boolean blnoption
byt Byte bytage
cur Currency curitr
dte Date dteinventory
dbl Double dbllongnumbers
int Integer intyearlevel
Ing Long lngspeed
obj Object objpresentation
sng Single sngincome
str String strname

 Used to reference object's properties and methods in code


- Object dot Property
o Form.Text, TextBox. Text
- Object dot Method
o Form.Hide(), TextBox.Focus()
 To reference an object's events use an underscore in the Private Sub name and use a dot in the Handles subclause of the Private Sub
statement
Coding Part 4: Converting between variable types
Conversion
 Convert between items
 Use a Ctype function

Example
*Dim anlntegerAs Integer = 54
MsgBox (CStr(anlnteger))
This will convertanlnteger= 54
to output as a string "54"

KINDS OF DATA TYPES


Seven Numeric Data Types
Type Storage Range
Byte 1 byte 0 to 255
Integer 2 bytes -32,768 to 32,768
Long 4 bytes -2,147,483,648 to 2,147,483,648
Single 4 bytes -3.402823E+38 to -1.401298E-45 or
1.401298E-45 to 3.402823E+38
Double 8 bytes -1.79769313486232E+308 to
-4.94065645851247E-324 or
4.94065645851247E-324 to
1.79769313486232E+308
Currency 8 bytes -922,337,203,685,477.5808 to
922,337,203,685,477.5808
Decimal 12 bytes +/- 79,228,162,514,264,337,593,543,950,335
This if no decimal
+/- 79,228,162,514,264,337,593,543,950,335

VB.NET COMMONLY USED COMMAND and PROPERTIES


Tools/Objects PREFIXES used in VB.Net
TOOLS PREFIX
Textbox txt
Label Ibi
Button btn or cmd
Radio Button rdo
Combo Box cmb
Check Box Chk or chkb
Form frm

Common properties of FORM


 Background Image
 Autosize
 Back Color
 Form Border style
 Icon

Common properties of TEXTBOX


 Font
 ForeColor
 PasswordChar
 ReadyOnly
 Text Align

Combo Box Common properties


Collection
 BackColor
 Forecolor
 DropDownStyle
 Font

o If statement/ USING LOGIN


o LOGIN VB/YES NO
o Messagebox stye
o Show form
o Hide form
o Read only
o Clear text
o Text enable/ text disable
o Combo box

VB Default Controls
List Box, Combo Box
Default Controls
- Pointer
- Picture Box
- Label
- Text Box
- Frame
- Command Box
- Checkbox
- Option Button
- Combo box
- List box
- Horizontal box
- Vertical scroll Bar
- Timer
- Drive List Box
- Directory list box
- File list box
- Shape
- Line
- Image
- Data

The Combo Box


 Enables you to present lists to the users
 can be used in three different forms:
- The drop-down combo box: Presents the users with a text box combined with a dropdown list. The users can either select an
item from the list portion or type an item in the text box portion
- The simple combo box: Displays a text box and a list that doesn't drop down the users can either select an item from the list
portion or type an item in tie text box portion.
- The drop-down list: Displays a drop down list box from which the users can make a choice. The users cannot enter items that
are not in the list.

ADD ITEM
Combobox1.items.add("January") = Constant variable
Combobox1.items.add("textbox.text") = Indefinite Variable

COMBO BOX FOR LOOP


Dim i As Integer = O
For I = 1 to 60
ComboBox1.ltems.Add(i)
Next

List Box, Combo Box


List Box
List Box control can used the to present a list of choices.
The key parts of the list box are the following:
- Item list: This is the list of items from which the users can select. These items are added to the list in the design environment or by the
program as it is running.
- Selected item: This item is chosen by the users.
- Scrollbar: This part indicates that more items are available on the list than will fit in the box.

Listbox add item


ListBox1.items.Add(“orange”) CONTANT VARIABLE
ListBox1.items.Add(TextBox1.Text) INDEFINITE VARIABLE

Adding Items to List Box at design-time


 List box items can be added at design time by using the "List" property of the control.
 After you add an item to the list, press Ctrl+Enter to move to the next line of the list.
Adding Items to List Box at Programmatically
Using add Item method:
Example.
Private Sub Form_Load()
Dim i As Integer
For I = 1 To 100
List1.AddItem "This is item & i
Next i
End Sub

Other List Box Methods & properties


To clear all the items in a list box. use the Clear method
- List1.Clear
To refer to a list item use the list() array:
- List1.list(0) First Term
- List1.list(1) Second Term
ListCount represents the number of items a list box.
For I = 0 To List1.ListCount = 1
Print List1.List(i)

Listbox clear items


ListBox1.ltems.clear

List Box Items Positlon


To add item a specific position (index):
- lstAvailable.AddItem “Apples”, 2
To sort list box item. set the Sorted property to True.
(designtime only)
Working with Multiple Selections
Listindex property only a single selection
You have to examine each item the 1st to determine whether it is selected
Whether an item is selected is indicated by the list box's
Selected property
- True (item selected)
- False (item not selected)
- Example
For i = 0 to List1 ListCount – 1
If List1.Selected(i) Then Print List1.List(i)
Next i

Combo Box features


 Use the Add Item, Removeltem, and Clear methods to modify the contents of the list.
 Sorted or an unsorted list.
 Support the ItemData array and Newlndex property.
 No multiple choices
 Combo boxes Allows the users to enter choices that are not on the list.
 Drop-down list is useful for presenting several choices in a small amount of space.

Creating a Combo Box


 Draw a combo box on your form
 Select its style from the property window
 Add items to the List property at design or run time
VB PART 4
RADIO BUTTON & PICTURE BOX

The RadioButton control is used to provide a set of mutually exclusive


options. The user can select one radio button in a group. If you need to
place more than one group of radio buttons in the same form, you should
place them in different container controls like a GroupBox control.

Properties of the RadioButton Control


Sr.No. Property & Description
1 Appearance
Gets or sets a value determining the appearance of the radio button.
2 AutoCheck
Gets or sets a value indicating whether the Checked value and the appearance of the control automatically change when the control
is clicked

3 CheckAlign
Gets or sets the location of the check box portion of the radio button.
4 Checked
Gets or sets a value indicating whether the control is checked.
5 Text
Gets or sets the caption for a radio button.

Properties of the PictureBox Control


Image
Gets or sets the image that is displayed in the control.
SizeMode
Determines the size of the image to be displayed in the control. This property takes its value from the PictureBoxSizeMode enumeration. which
has values -
Normal - the upper left corner of the image is placed at upper left part of the picture box
Strechlmage - allows stretching of the image
AutoSize - allows resizing the picture boxto the size of the image
Centerlmage - allows centering the image in the picture box
Zoom - allows increasing or decreasing the image size to maintain the size ratio.

PICTURE BOX
• Picture box is a control in Visual Basic that is used to display images

Loading an Image at Runtime


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load PictureBox1.Image =
Image.FromFiIe ( "C: \ \ fish.ipg") End
VB
PART 5
CHECKBOX
CHECKBOX CONTROL
VB.NET CheckBox Control
The CheckBox control is a control that allows the user to select or deselect options from the available options. When a checkbox is selected, a
tick or checkmark will appear on the Windows form

CheckBox Properties
Property Description
DefauIt It is used to get the default size of the checkbox.
AutoCheck The AutoCheck property is used to check whether the checked value or appearance of control can be automatically changed
when the user clicked on the CheckBox control.
CheckAlign It is used to set the checkmark's alignment. such as horizontal or vertical on the checkbox.
Appearance The Appearance property is used to display the appearance of a checkbox control by setting a value.
CheckState The CheckState property is used to verify whether the checkbox status is checked in the window form.
ThreeState The ThreeState property is used to check whether the control allows one to set three check positions instead of two by
setting values.
FlatStyle It is used to obtain or set the flat appearance of a checkbox.
VB PART 6
LISTVIEW
The ListView control is used to display a list of items. Along with the TreeView control, it allows you to create a Windows Explorer
like interface.

Let's click on a ListView control from the Toolbox and place it on the form.

The ListView control displays a list of items along with icons. The Item property of the ListView control allows you to add and
remove items from it. The SelectedItem property contains a collection of the selected items. The MultiSelect property allows you to set
select more than one item in the list view. The CheckBoxes property allows you to set check boxes next to the items.
Properties of the ListView Control
The following are some of the commonly used properties of the ListView control –

Sr.No Property & Description


Alignment
1
Gets or sets the alignment of items in the control.
GridLines
8 Gets or sets a value indicating whether grid lines appear between the rows and columns containing the items and subitems in the
control.
HeaderStyle
9
Gets or sets the column header style.
Items
14
Gets a collection containing all items in the control.
SelectedItems
21
Gets the items that are selected in the control.
View
Gets or sets how items are displayed in the control. This property has the following values:
 LargeIcon − displays large items with a large 32 x 32 pixels icon.
28  SmallIcon − displays items with a small 16 x 16 pixels icon
 List − displays small icons always in one column
 Details − displays items in multiple columns with column headers and fields
 Tile − displays items as full-size icons with item labels and sub-item information.

Methods of the ListView Control


The following are some of the commonly used methods of the ListView control −

Sr.No. Method Name & Description


Clear
1
Removes all items from the ListView control.
1 ToString
Returns a string containing the string representation of the control.
VB - PART 7
INTRODUCTION TO DATABASE CONNECTION USING MICROSOFT ACCESS
Microsoft access database
What is the code to clear listbox items? *
ListBox1.ltems.clear
This part of VB GUI, Provides you with a way to navigate through your program's structure, with entries for each form module etc. *
Solution Explorer Window
Give another one COMMON property of a FORM? *
Background Image
This part of VB GUI, Contains Control and other component that can be placed on the form designer. *
Toolbox
What is the standard Prefix used for text box? k
txt
It is a drop down style that only READ ITEMS given in a COMBO BOX *
Clear text
What is the standard Prefix used for button? *
btn or cmd
Give 1 Visual Studio Environment *
Toolbox
Give at least 1 drop down style of a Combo box k
The drop-down list
Give one COMMON property of a COMBO BOX
DropDownStyle
This part of VB GUI, will be populated with any potential issues with the code *
Error/Task List Window
Give 1 Visual Studio Environment *
Solution Explorer Window
Declaring of items in listbox can be blank variables or blank variables *
Constant
Give one COMMON property of a TEXTBOX *
Font
What is the hot key to run the program in VB.NET? *
F5

What is the standard Prefix used for check box? *


Chk or chkb
In VB Current form may be referenced as
VB.NET
Also known as Remark Statement k
REM Statement
What is the standard Prefix used for label? *
Lbl

This part of VB GUI, Describes the properties or characteristics of the form and other controls.
Properties Window
This part of VB GUI, Design space that contains objects or Controls *
Toolbox
File extension of "Project Files" in VB.Net *
.vb
Give one COMMON property of a FORM? *
Form Border style
What is the code to add an item in listbox? *
Given: Listbox 1
Given: Apple
ListBox1.items.Add("Apple")
What is the code to clear item in a combo box? *
Given: Combobox1
Combobox1.ltems.clear

You might also like