0% found this document useful (0 votes)
21 views

Visual Basic (VB)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Visual Basic (VB)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

VISUAL BASIC (VB)

LITTLE STORY ABOUT VB

 Inspiration: The graphical user interface (GUI) design concept for VB came
from Alan Cooper's "Tripod" prototyping tool.
 First Release: The official launch of Visual Basic 1.0 happened in 1991, just
a year after Windows 3.0. It was designed for the Windows environment,
unlike an earlier attempt for DOS.
 Focus: VB aimed to make programming more accessible, especially for
beginners. Its drag-and-drop interface and focus on rapid application
development (RAD) made it a hit.
 Evolution: VB.NET
USES OF VB

 Visual basic is an event-driven and Object Oriented programing language use for
rapid application development.
 Rapid Application Development (RAD).
 Desktop Applications.
 Database Access.
 Learning Programming.
VARAIBLES
• Visual Basic (.NET) offers a variety of data types to store different kinds of information in
your programs.
• Rules in naming Variables in VB.
• Start with a letter.
• Use letters, numbers, and underscores.
• No reserved keywords.
• Case-sensitive.
• Implicit typing and Explicit typing.
• When declaring a variable in vb you use the key word ‘Dim’ follow by the variable name.
• Example code:
• Dim age As Integer = 25 ' Declares a variable 'age' to hold an integer value of 25
• Dim pi As Double = 3.14159 ' Declares a variable 'pi' with the value of pi
• Dim distance = 10.5 ' Another example of assigning a decimal value to a Double
variable.
• Dim name As String = "Alice" ' Declares a variable 'name' to hold a string "Alice"
• Dim message = "Hello, world!" ' Another example of assigning text to a String variable
OPERATORS

Binary Unary Assignment Comparism Equations


Operators Operators Operators Operators Operators

+ ++ += < =
- -- -= > <>
* + *= <=
/ - /= >=
% a%=2 or
a = a%2
=
CONDITIONS
• Visual Basic.NET (VB.NET) offers several conditional statements to control the flow of your program based on certain
criteria. Here are some of them;
1. If...Then...Else:

Dim age As Integer = 20

If age >= 18 Then


Console.WriteLine("You are eligible to vote.")
Else
Console.WriteLine("You are not eligible to vote.")
End If

2. If...Then...Else If...Else:

Dim grade As Char = "B"

If grade = "A" Then


Console.WriteLine("Excellent work!")
Else If grade = "B" Then
Console.WriteLine("Good job!")
Else
Console.WriteLine("Keep practicing!")
End If
1. Select Case:

Dim dayOfWeek As Integer = 2

Select Case dayOfWeek


Case 1
Console.WriteLine("Monday")
Case 2
Console.WriteLine("Tuesday")
Case Else
Console.WriteLine("Not Monday or Tuesday")
End Select

2. Logical Operators (And, Or, Not):

Dim isLoggedIn As Boolean = True


Dim hasPermission As Boolean = False

If isLoggedIn And hasPermission Then ' Both conditions must be true


Console.WriteLine("Access granted")
Else
Console.WriteLine("Access denied")
End If
LOOPS
VB OFFER US A VARIETY OF LOOP SUCH AS:

 1. For...Next Loop:
For i As Integer = 1 To 5 ' Loop 5 times from i = 1 to i = 5
Console.WriteLine("Iteration: " & i)
Next
2. For Each...Next Loop:
Dim names As String() = {"Alice", "Bob", "Charlie"}

For Each name In names


Console.WriteLine(name) ' Print each name in the array
Next
3. While...End While Loop:

Dim count As Integer = 0

While count < 3 ' Loop until count reaches 3


Console.WriteLine("Count: " & count)
count += 1 ' Increment count by 1
End While

4. Do...Loop Loop:

Dim input As String

Do
Console.WriteLine("Enter your name (or 'exit' to quit):")
input = Console.ReadLine()
Loop While input.ToLower <> "exit" ' Loop until user enters "exit"
FUNCTIONS
HOW TO CREATE FUNCTIONS IN VB.

 In Visual Basic.NET (VB.NET), functions are reusable blocks of code that perform
specific tasks and return a value to the calling code.
 The general syntax for creating a function in VB.NET is:

[Access modifier] Function FunctionName([ParameterList]) As ReturnType


' Function body (code to be executed)
Return returnValue ' Optional, specifies the value to return
End Function
TYPES OF FUNCTIONS

 Subroutines (Void Functions): These functions do not return a value and


are primarily used to perform actions or modify data. Usually define using
‘Sub’ instead of ‘Function’ and no return type.
 Value-Returning Functions:hese functions perform calculations,
manipulations, or data retrieval and return a single value back to the calling
code. The ‘As Return Type’ specifies the data type of the returned value.
 Multiple Value-Returning Functions (Not Common): While not as common,
VB.NET allows returning multiple values from a function using structures
or arrays. This approach is less common due to potential readability issues.
EXAMPLE CODE OF FUNCTIONS

Sub GreetUser(name As String) Function CalculateArea(length As


Double, width As Double) As Double
Console.WriteLine("Hello, " & name &
"!") Dim area = length * width
End Sub Return area
End Function
VB GUI
WHAT TO KNOW

 Forms:  GUI Development with VB:


 Drag-and-Drop Design: Arrange
controls on the form using drag-and-
 Represent windows on the screen that drop functionality.
display information and allow user
 Properties: Set properties of each
interaction.
control to customize appearance and
behavior (e.g., text, size, color).
 Designed visually using the Toolbox in  Event Handling: Write code to respond
the VB development environment. to user interactions with the controls
(e.g., button clicks, text changes).
 Contain various UI elements (controls)  Code-Behind: Code associated with
like buttons, text boxes, labels, and the form resides in a separate file for
more. better organization.
BENEFITS OF USING FORMS:

•Visual Design: Easy to create user interfaces without extensive knowledge of low-level graphics programming.

•Event-Driven Programming: Code reacts to user interactions, making the application interactive.

•Rich Set of Controls: VB offers a variety of controls to cater to different UI needs.

You might also like