Visual Basic Language
 A storage location in memory (RAM)   Holds data/information while the program is running   These storage locations can...
   You the programmer make up a name for the    variable   Visual Basic associates that name with a    location in the c...
Data type - Specifies type of data variable can store   Integer variables: Long, Integer, Short, Byte   Floating-point v...
Data type   Prefix Size    ValuesByte        byt   1 byte   positive integer value from 0 to 255Short       shr   2 byte  ...
 First character must be a letter or underscore Must contain only letters, numbers, and  underscores (no spaces, periods...
 A variable declaration is a statement that  creates a variable in memory Syntax: Dim VariableName As DataType  Dim (sh...
 A starting or initialization value may be  specified with the Dim statement Good practice to set an initial value unles...
 Variable MUST be declared prior to the code where they are used Variable should be declared first in the procedure (sty...
Data type           Default (Initial) valueAll numeric types   Zero (0)Boolean             FalseChar                Binary...
 What – Indicates the part of the program where the  variable can be used When – From the variable declaration until the...
 What – Indicates the part of the program where the  variable exists in memory When – From the beginning of the code blo...
   Arithmetic Operators    ^        Exponential    *        Multiplication    /        Floating Point Division           ...
   Examples of use:     decTotal = decPrice + decTax     decNetPrice = decPrice - decDiscount     dblArea = dblLength ...
   This operator can be used in place of the    backslash operator to give the remainder of a    division operation    in...
   Concatenate: connect strings together   Concatenation operator: the ampersand (&)   Include a space before and after...
   Often need to change the value in a variable and    assign the result back to that variable   For example: var = var ...
 Parenthesis Exponential Multiplication / Division Integer Division MOD Addition / Subtraction String Concatenation...
 6 * 2 ^ 3 + 4 / 2 = 507*4/2–6=8 5 * (4 + 3) – 15 Mod 2 = 34   intX = 10   intY = 5   intResultA = intX + intY * 5  ...
If Condition Then   [statements]       End If
If Condition Then     [statements]Else If Condition Then     [statements]         End If
 If your program can handle multiple values of  a particular variable and you don`t want to  stack up a lot of If Else to...
Select Case testexpression[Case expressoinlist-n[Statement-n]][Case ElseElse statement]]End Select
Module Module1 Sub Main()Dim intNumber As IntegerSystem.Console.WriteLine("enter integer number....")intNumber = Val(Syste...
Loop is used to execute a series of statements repeatedlyBUT doesn`t mean you perform one identical task repeatedly, you m...
Keeps executing its enclosed statements While or Until (depending on which keyword you use, While or Until) condition is t...
Do [{while|until}condition][statements][Exit Do][statements]Loop                         ORDo[statements][Exit Do][stateme...
Module Module1Sub Main()   Dim a As Integer   a=1   Do While a < 100     a=a*2     System.Console.WriteLine("Product is::"...
Module Module1 Sub Main()   Dim i As Integer   For i = 1 To 10    System.Console.WriteLine(i)   Next i  System.Console.Rea...
They are a series of statements that are executed when called. Methods allow us to handle code in a simple and organized f...
Sub procedures are methods which do not return a value. Each time when the Sub procedure is called the statements within i...
Module Module1 Sub Main() sub procedure Main() is called by default Display() sub procedure display() which we are creatin...
Function is a method which returns a value.  Functions are used to evaluate data, make  calculations or to transform data....
Imports System.Console   Module Module1   Sub Main()   Write("Sum is"&""&Add())   calling the function   End Sub   Public ...
A method is not executed until it is called. A method is called by referencing its name along with any required parameters...
Variables declared within methods are called method variables. They have method scope which means that once the method is ...
A parameter is an argument that is passed to the method by  the method that calls it. Parameters are enclosed in  parenthe...
END OF CHAPTER TWO     THANYOU
Vb language2
Vb language2
Upcoming SlideShare
Loading in …5
×

Vb language2

331 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
331
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Vb language2

  1. 1. Visual Basic Language
  2. 2.  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can be referred to by their names Every variable has three properties:  Name - reference to the location - cannot be changed  Value - the information that is stored - can be changed during program execution, hence the name “variable”  Data Type - the type of information that can be stored - cannot be changed
  3. 3.  You the programmer make up a name for the variable Visual Basic associates that name with a location in the computers RAM The value currently associated with the variable is stored in that memory location You simply use the name you chose when you need to access the value
  4. 4. Data type - Specifies type of data variable can store Integer variables: Long, Integer, Short, Byte Floating-point variables: Single, Double Fixed decimal point variable: Decimal Boolean variables: True, False Character variable: Char Text variable: String The Object variable  Default data type assigned by Visual Basic  Can store many different types of data  Less efficient than other data types
  5. 5. Data type Prefix Size ValuesByte byt 1 byte positive integer value from 0 to 255Short shr 2 byte integer from –32,768 to +32,767Integer int 4 byte integer from +/- 2,147,483,647Long lng 8 byte integer from +/- 9,223,372,036,854,775,807Single sng 4 byte single-precision, floating-point numberDouble dbl 8 byte double-precision, floating-point numberDecimal dec 16 byte number with up to 28 significant digitsChar chr 2 byte Any single characterBoolean bln 2 byte True or FalseString str (4 byte) Text - Any number/combination of charactersDate dtm 8 byte 8 character date: #dd/mm/yyyy#Object obj (4 byte) An address that refers to an object
  6. 6.  First character must be a letter or underscore Must contain only letters, numbers, and underscores (no spaces, periods, etc.) Can have up to 255 characters Cannot be a VB language keyword Naming Conventions  Should be meaningful  Follow 3 char prefix style - 1st 3 letters in lowercase to indicate the data type  After that, capitalize the first letter of each word  Example: intTestScore
  7. 7.  A variable declaration is a statement that creates a variable in memory Syntax: Dim VariableName As DataType  Dim (short for Dimension) - keyword  VariableName - name used to refer to variable  As - keyword  DataType - one of many possible keywords to indicate the type of value the variable will contain Example: Dim intLength as Integer
  8. 8.  A starting or initialization value may be specified with the Dim statement Good practice to set an initial value unless assigning a value prior to using the variable Syntax: Dim VariableName As DataType = Value  Just append " = value” to the Dim statement  = 5  assigning a beginning value to the variable Example: Dim intLength as Integer = 5
  9. 9.  Variable MUST be declared prior to the code where they are used Variable should be declared first in the procedure (style convention) Declaring an initial value of the variable in the declaration statement is optional
  10. 10. Data type Default (Initial) valueAll numeric types Zero (0)Boolean FalseChar Binary 0String or Object EmptyDate 12:00 a.m. on January 1, 0001
  11. 11.  What – Indicates the part of the program where the variable can be used When – From the variable declaration until the end of the code block (procedure, method, etc.) where it is declared  Variable cannot be used before it is declared  Variable declared within a code block is only visible to statements within that code block ▪ Called Local Variable  Can be declared at the beginning of the class code window (General Declarations section) and be available to all blocks ▪ Called Form Level Variable  Variables that share the same scope cannot have the same name (same name ok if different scope)
  12. 12.  What – Indicates the part of the program where the variable exists in memory When – From the beginning of the code block (procedure, method, etc.) where it is declared until the end of that code block  When the code block begins the space is created to hold the local variables ▪ Memory is allocated from the operating system  When the code block ends the local variables are destroyed ▪ Memory is given back to the operating system
  13. 13.  Arithmetic Operators ^ Exponential * Multiplication / Floating Point Division Integer Division MOD Modulus (remainder from division) + Addition – Subtraction & String Concatenation (putting them together)
  14. 14.  Examples of use:  decTotal = decPrice + decTax  decNetPrice = decPrice - decDiscount  dblArea = dblLength * dblWidth  sngAverage = sngTotal / intItems  dblCube = dblSide ^ 3
  15. 15.  This operator can be used in place of the backslash operator to give the remainder of a division operation intRemainder = 17 MOD 3 ‘result is 2 dblRemainder = 17.5 MOD 3 ‘result is 2.5 Any attempt to use of the or MOD operator to perform integer division by zero causes a DivideByZeroException runtime error
  16. 16.  Concatenate: connect strings together Concatenation operator: the ampersand (&) Include a space before and after the & operator How to concatenate character strings  strFName = “Bob"  strLName = "Smith"  strName = strFName & " “  “Bob ”  strName = strName & strLName  “Bob Smith”  intX = 1 intY = 2  intResult = intX + intY  strOutput = intX & “ + “ & intY & “ = “ & intResult  “1 + 2 = 3”
  17. 17.  Often need to change the value in a variable and assign the result back to that variable For example: var = var – 5 Subtracts 5 from the value stored in var Operator Usage Equivalent to Effect += x += 2 x=x+2 Add to -= x -= 5 x=x–5 Subtract from *= x *= 10 x = x * 10 Multiply by /= x /= y x=x/y Divide by = x = y x=xy Int Divide by &= x &= “.” x = x & “.” Concatenate
  18. 18.  Parenthesis Exponential Multiplication / Division Integer Division MOD Addition / Subtraction String Concatenation Relational Operators (< , > , >= , <= , <>) Logical Operators (AND, OR, NOT)
  19. 19.  6 * 2 ^ 3 + 4 / 2 = 507*4/2–6=8 5 * (4 + 3) – 15 Mod 2 = 34 intX = 10 intY = 5 intResultA = intX + intY * 5 iResultA is 35 iResultB = (intX + intY) * 5 iResultB is 75 dResultA = intX - intY * 5 dResultA is -15 dResultB = (intX - intY) * 5 dResultB is 25
  20. 20. If Condition Then [statements] End If
  21. 21. If Condition Then [statements]Else If Condition Then [statements] End If
  22. 22.  If your program can handle multiple values of a particular variable and you don`t want to stack up a lot of If Else to handle them, you should consider Select Case We use Select Case to test an expression, determine which of several cases it matches and execute the code
  23. 23. Select Case testexpression[Case expressoinlist-n[Statement-n]][Case ElseElse statement]]End Select
  24. 24. Module Module1 Sub Main()Dim intNumber As IntegerSystem.Console.WriteLine("enter integer number....")intNumber = Val(System.Console.ReadLine()) Select Case intNumber Case 1System.Console.WriteLine("10q") Case 2 System.Console.WriteLine("OK")Case 3 To 7System.Console.WriteLine("it is b/n 3 and 7")Case Is > 7System.Console.WriteLine("10q") Case ElseSystem.Console.WriteLine("i don`t know nthis number")End SelectSystem.Console.ReadLine()End SubEnd Module
  25. 25. Loop is used to execute a series of statements repeatedlyBUT doesn`t mean you perform one identical task repeatedly, you might be operating on Different data items each time through the loop
  26. 26. Keeps executing its enclosed statements While or Until (depending on which keyword you use, While or Until) condition is true
  27. 27. Do [{while|until}condition][statements][Exit Do][statements]Loop ORDo[statements][Exit Do][statements]
  28. 28. Module Module1Sub Main() Dim a As Integer a=1 Do While a < 100 a=a*2 System.Console.WriteLine("Product is::" & a) Loop System.Console.ReadLine()End SubEnd Module
  29. 29. Module Module1 Sub Main() Dim i As Integer For i = 1 To 10 System.Console.WriteLine(i) Next i System.Console.ReadLine() End SubEnd Module
  30. 30. They are a series of statements that are executed when called. Methods allow us to handle code in a simple and organized fashion. There are two types of methods in VB .NET: those that return a value (Functions) and those that do not return a value (Sub Procedures).
  31. 31. Sub procedures are methods which do not return a value. Each time when the Sub procedure is called the statements within it are executed until the matching End Sub is encountered.Sub Main(): the starting point of the program itself is a sub procedure. When the application starts execution, control is transferred to Main Sub procedure automatically which is called by default.
  32. 32. Module Module1 Sub Main() sub procedure Main() is called by default Display() sub procedure display() which we are creating End Sub Sub Display() System.Console.WriteLine("Using Sub Procedures") executing sub procedure Display() End Sub End Module
  33. 33. Function is a method which returns a value. Functions are used to evaluate data, make calculations or to transform data. Declaring a Function is similar to declaring a Sub procedure. Functions are declared with the Function keyword.
  34. 34. Imports System.Console Module Module1 Sub Main() Write("Sum is"&""&Add()) calling the function End Sub Public Function Add() As Integer declaring a function add Dim i, j As Integer declaring two integers and assigning values to them i = 10 j = 20 Return (i + j) performing the sum of two integers and returning its value End Function End Module
  35. 35. A method is not executed until it is called. A method is called by referencing its name along with any required parameters. For example, the above code called the Add method in Sub main like this: Write("Sum is" & " " & Add()).
  36. 36. Variables declared within methods are called method variables. They have method scope which means that once the method is executed they are destroyed and their memory is reclaimed. For example, from the above code (Functions) the Add method declared two integer variables i, j. Those two variables are accessible only within the method and not from outside the method.
  37. 37. A parameter is an argument that is passed to the method by the method that calls it. Parameters are enclosed in parentheses after the method name in the method declaration. You must specify types for these parameters. The general form of a method with parameters looks like this:Public Function Add(ByVal x1 as Integer, ByVal y1 as Integer) ------------ Implementation ------------ End Function
  38. 38. END OF CHAPTER TWO THANYOU

×