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

Slides

Uploaded by

mnmengwai
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)
22 views

Slides

Uploaded by

mnmengwai
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/ 50

VB.

NET
Programming 511
Lecturer: Frans Rampai

Semester 1 2018
Section A: Introduction
Study Materials:
Programming 511 Learner guide( key)
YouTube Visual Basic Tutorial by thenewboston
Programming with Microsoft Visual Basic 2012
Study materials are not limited to the above mentioned.

Types of programming languages:


VB.Net,C#,C++,Python,Php,Java,etc.
Section A: Introduction
Programming 511 Tools
IDE – Integrated development environment i.e. Microsoft Visual Studio.
VB.Net

Student Assessments
2 Tests
One Assignment
One Exam
Section A: Introduction
What is programming Language?
Compiler understandable set of instructions used to build a software.
Compiler: IDE sub software that validate the code written by the
programmer.

Types of programmers?
Backend and frontend , Frontend design the look of the software and
backend write the code.
Section A: Introduction
IDE-Integrated Developmet Environment
Section A: Introduction
• Two types of Applications: Console Application(no interface) and
Windows Forms Application(Drag and drop)
• How to create Console Application:Click File>New>Project>Visual
Basic>Console Application>then name your application and click OK.
Section A: Introduction
• How to create Windows Forms Application: Click
File>New>Project>Visual Basic> Windows Forms Application >then
name your application and click OK.
Section B: Variables and Data Types
• Variable= A name/character that store data.
• Data type specify the type of data that a variable is allowed to contain.
Data Types

Primitive Non-Primitive

String
Numeric Logical Character
Array
Boolean
Char Etc
Integer Floating-point

Byte Long

Short Float Double


Int
Section B: Variables and Data Types
• Declaring a variable: Dim varName As DataType.
• Dim(Dimension) – create and allocate storage for a variable based on data
type.
• Primitive types: Most basic data types available with vb.net language.
• They serve only one purpose-containing pure, simple values of a kind.
They are predefined data types.
• Non-primitive: They are not defined b y the programming language
but are instead created by the programmer.
• They are often called reference variables or object references
since they reference memory location .
• Integer: cannot contain a decimal value.
• Byte: allowed value:0 to 255, 8 bit size
• Short: allowed value:-32768 to 32767
• Int: allowed value: -32 768 to 32767, 16 bit size
• Long: allowed value: -2147483648 to 2147483647 ,32 bit size
Section B: Variables and Data Types
• Floating-point: can contain decimal values.
• Double :allowed values: 64 bit floating point, range about 10^38.
• Float : allowed value: store double precision float numbers, 17 bit

• Logical: Can be assigned either True or False.


• BOOLEAN: e.g. Dim overflow As Boolean=True
• Character: store only one character.
• Char: allowed values: alphabet letters and symbols e.g. Dim currency As Char = “R” or “$”

• Non-Primitive types: programmer defined data types; object references.


• String: allowed value: Dim strVar As String =“ABCDE” or = “2468”
• Array: allowed value: Dim arrName As Array={“Botswana”, “Lesotho”} or
={2,4,6,8}
Section B: Variables and Data Types
• Ways to declare a variable:
Section C: Comments and Error Types
• Comments : statement that explain the code, ignored by compiler.
• Hyphen is used to write a comment e.g

Error types:
• Runtime Error: e.g user denied access. Unavailable requested resource.
• Syntax Error: Wrong Language e.g Console.ReadLine(
• Logic Error: Lack of Console.ReadLine(). Wrong calculations.etc
Section D:Operators
• Maths Operators:
Addition(+), Multiplication( *), Division( /), Modulus(Mod), +=,*=,-=,/=

Examples: Output:
Sum=5

Output:
Remainder=1
Section D:Operators
• Conditional operators:
< less than
> Greater than
= Equal to
>= Greater than or equal to
<= Less than or equal to
<> Not equal to
Section D:Operators
• Logical Operators:
And
Or
Section D:Operators
• Program Flow: Compiler read the code from top to bottom.

Output?
Section E: Control Structures
• Control structures enable programs to make decisions.
• If statement:
If <condition> Then
statements
ElseIf <condition> Then
statements
Elsstatements
End If
Section E: Control Structures
If statement.
Section E: Control Structures
If statement
Section E: Control Structures
Nested If statement
Section E: Control Structures
Nested If statement
Section E: Control Structures
• Select statement: same as if statement
Select <selector>
Case 1
statement
Case 2
statement
Case Else
statement
End Select
Section F: Strings
• Concatenating string: combining strings
• We use & or + to concatenate two or more strings.

Output:
Section F: Strings
• Length Method: count characters including space
Section F: Strings
• Substring Method: Cut out part of string using index.

• Replace: Replace part of string with another.


Section F: Strings
• ToUpper() Method: Turn lower characters into upper case, ToLower()
does opposite.

• CompareTo() Method. Output of 1 means the two strings compared have same number of
characters, 0 means compared strings are identical and -1 means the compared strings have
unequal characters.
Section G: Repetition/Loop Structures
• For Next Loop:

• Step Operator: specify the number of steps per For Next Loop, default
is 1.
Section G: Repetition/Loop Structures
• Exit For: Quit For Next Loop when condition is true.

• Do Until Loop: repeat statements until condition is true


• Do While Loop: repeat code until condition is true.
• Exit Do: Quit Do Until/While when condition is true.
• Continue For: Jumps the For Next Loop when condition is true.
Section G: Repetition/Loop Structures
• Nested loops: loop inside loop. e.g. For Next inside For Next Loop.

• Infinite Loop: Loops without ending. e.g.


Do
Console.WriteLine(“Hello World”)
Loop While True
Section H: Introduction to windows Forms
Application
• Good bye to the console and welcome to Windows Forms.
• From Properties:

• Message Box Application:


Section H: Introduction to windows Forms
Application
• You are going to work with the properties of controls, for instance
changing the default name “Button1” to “btnHello” is crucial.
• Just like you give variables meaningful names same applies to controls.
Section H: Introduction to windows Forms
Application
• Properties of Controls:Name,BackgroundColor,BorderStyle,MaximizeBox,MinimizeBox,Opercity,etc.
• Controls in a ToolBox: Button, CheckBox,ComboBox,ListBox,NotifyIcon,ToolTip,etc.
• InputBox: This is a message that allow user to input data ,Example:
Section H: Introduction to windows Forms
Application
Section I: Functions and Sub procedures
• Sub procedure is a function that does not return a value.
Section I: Functions and Sub procedures
• A function is a block of code that solve a particular problem.
• Example:
Section I: Functions and Sub procedures:
ByVal and ByRef
• Parameter is a variable declared within the parenthesis of a
function/sub procedure.
• Argument is the value/variable that represent the value of parameter
when a function/sub procedure is called/invoked.
• Parameters and arguments must have same data type.
• ByVal-parameter passed by value can be assigned a value inside its
function, since its only a copy of parameter.
• ByRef-parameter passed by reference be assigned a value even
outside its function, since it’s the original parameter.
Section I: Functions and Sub procedures:
ByVal and ByRef
Section I: Functions and Sub procedures:
Coercion
• This is the use of an optional data type
• You want the user to pass for instance a double value or integer value.
Section I: Functions and Sub procedures
• Exit Sub- used to quit the Sub procedure based on given condition.
• Global variables –variable declared outside any sub procedure or
function within the class, it’s accessible anywhere in a class.
• Constants: Variables that you can use anywhere in your program
without the having to chang e.g. pie,account number, etc.
Section I: Functions and Sub procedures
Section I: Functions and Sub procedures:
Maths Class
• Maths class provide predefined calculation methods and properties.
Section I: Functions and Sub procedures:
CTYPE(Converting data types)
• Note:Everything entered into a textbox is string data type by default.
Section I: Functions and Sub procedures:
CTYPE(Converting data types)
Section J: Arrays
• Array refers to a group of variables with same data type.
• Array declaration and initialization:
Dim arrName(total) As dataType
OR
Dim arrName As dataType={var1,var2,bar3,…}
• Array assignment: First item is represented by index 0.
• E.g. arrName(0)=“Botswana”
• i.e. Dim arrName(2) As dataType : imples the array will have 3
elements.
Section J: Arrays
Section J: Arrays
Section J: Arrays:
For Each Loop
• For Each Loop access array elements just as For Next Loop does.
Section J: Arrays:
Passing arrays as parameters
Section J: Arrays:
Passing arrays as parameters
The End:
Now that we reached the end remember and never take lightly:
In order for you to do best in this module you are strongly advised to
study harder and practice, consult anytime I’m free, use different study
materials and never allow anybody discourage you.

Good Luck.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy