14
Working With VB.NET Example For Console Applications Module Module1 Sub Main() System.Console.Write("Welcome to Console Applications") End Sub End Module Note the first line, we're creating a Visual Basic Module and Modules are designed to hold code. All the code which we write should be within the Module. Next line starts with Sub Main(), the entry point of the program. The third line indicates that we are using the Write method of the System.Console class to write to the console.

Vb (1)

  • View
    38

  • Download
    4

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Vb (1)

Working With VB.NET• Example For Console Applications

Module Module1Sub Main()System.Console.Write("Welcome to Console Applications")End SubEnd Module

Note the first line, we're creating a Visual Basic Module and Modules are designed to hold code. All the code which we write should be within the Module.Next line starts with Sub Main(), the entry point of the program.The third line indicates that we are using the Write method of the System.Console class to write to the console.

Page 2: Vb (1)

Working With VB.NET• Example For Windows Applications

Public Class Form1Inherits System.Windows.Forms.Form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)_Handles MyBase.LoadEnd SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As _System.EventArgs) Handles Button1.ClickMsgBox("Welcome to Forms") End SubEnd Class

Page 3: Vb (1)

Variables

• Variable is a storage area of the computer's memory

• Variables are declared with the Dim keyword. Dim stands for Dimension. In Variables lots of access specifiers are available.

• Access specifiers let's us specify how a variable, method or a class can be used. The following are the most commonly used one's:

Page 4: Vb (1)

Variables• Public: Gives variable public access which means that there is no restriction on their

accessibility• Private: Gives variable private access which means that they are accessible only

within their declaration content• Protected: Protected access gives a variable accessibility within their own class or a

class derived from that class• Friend: Gives variable friend access which means that they are accessible within the

program that contains their declaration• Protected Friend: Gives a variable both protected and friend access• Static: Makes a variable static which means that the variable will hold the value

even the procedure in which they are declared ends• Shared: Declares a variable that can be shared across many instances and which is

not associated with a specific instance of a class or structure• ReadOnly: Makes a variable only to be read and cannot be written

Page 5: Vb (1)

Variable Examples• Imports System .Console

Module Module1

Sub Main()Dim a,b,c as Integer'declaring three variables of type integera=10b=20c=a+bWrite("Sum of a and b is" & c)End Sub

End Module

Page 6: Vb (1)

Data Types in VB.Net• DATATYPE in a programming language describes that what type of data a

variable can hold . When we declare a variable, we have to tell the compiler about what type of the data the variable can hold or which data type the variable belongs to.

Page 7: Vb (1)

OperatorsArithmetic Operators Arithmetic operators are used to perform arithmetic operations that involve calculation of numeric values. The table below summarizes them:

Page 8: Vb (1)

OperatorsConcatenation Operators Concatenation operators join multiple strings into a single string. There are two concatenation operators, + and & as summarized below:

Comparison Operators A comparison operator compares operands and returns a logical value based on whether the comparison is true or not. The table below summarizes them:

Page 9: Vb (1)

OperatorsLogical / Bitwise Operators The logical operators compare Boolean expressions and return a Boolean result. In short, logical operators are expressions which return a true or false result over a conditional expression. The table below summarizes them:

Page 10: Vb (1)

Examples For OperatorsArithmetic Operators

Imports System.ConsoleModule Module1Sub Main()Dim x, y, z As Integerx = 30y = 20z = x + yWriteLine("Addition" & " = " & z)z = x - yWriteLine("Subtraction" & " = " & z)z = x * yWriteLine("Multiplication" & " = " & z)z = x / yWriteLine("Division" & " = " & z)Read()End SubEnd Module .

Page 11: Vb (1)

Examples For OperatorsConcatenation Operators

Imports System.ConsoleModule Module1

Sub Main()Dim str1, str2, str3, str4 As Stringstr1 = "Concatenation"str2 = "Operators"str3 = str1 + str2WriteLine(str3)str4 = str1 & str2WriteLine(str4)Read()End Sub

End Module

Page 12: Vb (1)

Examples For OperatorsConcatenation Operators

Imports System.ConsoleModule Module1

Sub Main()Dim str1, str2, str3, str4 As Stringstr1 = "Concatenation"str2 = "Operators"str3 = str1 + str2WriteLine(str3)str4 = str1 & str2WriteLine(str4)Read()End Sub

End Module

Page 13: Vb (1)

Examples For Operators• Comparison Operators

Imports System.ConsoleModule Module1Sub Main()Dim x, y As IntegerWriteLine("enter values for x and y ")x = Val(ReadLine())y = Val(ReadLine())If x = y ThenWriteLine("x is equal to y")ElseIf x < y ThenWriteLine("x is less than y")ElseIf x > y ThenWriteLine("x is greater than y")End IfRead()End SubEnd Module

Page 14: Vb (1)

Examples For Operators• Logical / Bitwise Operators

Imports System.ConsoleModule Module1

Sub Main()Dim x As Booleanx = Not 45 > 26WriteLine("x not is false")' x equals falsex = Not 26 > 87' x equals TrueWriteLine("x not is true")Read()End Sub

End Module