Visual Basic (VB)
Visual Basic (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
+ ++ += < =
- -- -= > <>
* + *= <=
/ - /= >=
% 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:
2. If...Then...Else If...Else:
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"}
4. Do...Loop Loop:
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:
•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.