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

Constants Modifiers Statements

Here are the steps to publish a VB.NET project: 1. In Solution Explorer, right-click on the project and select "Publish..." 2. In the Publish wizard, select the "Folder" publishing target. 3. Specify the publishing folder location (e.g. C:\Publish) 4. Uncheck "Create desktop shortcut" and "Create Start Menu shortcut" unless needed 5. Click "Publish" to compile and copy the necessary files to the publishing folder. This will package up your application, dependencies and runtime files into a folder that can be distributed and run on other machines independently of Visual Studio.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Constants Modifiers Statements

Here are the steps to publish a VB.NET project: 1. In Solution Explorer, right-click on the project and select "Publish..." 2. In the Publish wizard, select the "Folder" publishing target. 3. Specify the publishing folder location (e.g. C:\Publish) 4. Uncheck "Create desktop shortcut" and "Create Start Menu shortcut" unless needed 5. Click "Publish" to compile and copy the necessary files to the publishing folder. This will package up your application, dependencies and runtime files into a folder that can be distributed and run on other machines independently of Visual Studio.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Constants, Modifiers,

Statements
Modifiers
• The modifiers are keywords added with any
programming element to give some especial
emphasis on how the programming element
will behave or will be accessed in the program.

• Public, Private, Protected, Friend, Protected


Friend.
Methods
• A method is an action that an object can perform.
Properties
• A property is an attribute of an object that defines one of the object's
characteristics, such as size, color, or screen location, or an aspect of its
behavior, such as whether it is enabled or visible.
Events
• An event is an action recognized by an object, such as clicking the mouse or
pressing a key, and for which you can write code to respond. Events can
occur as a result of a user action or program code, or they can be triggered
by the system.
Class
• A class in Visual Basic is a template that defines the properties and
methods of an object.
Statements
• A statement is a complete instruction in Visual Basic
programs. It may contain keywords, operators,
variables, literal values, constants and expressions.
• Declaration statements − these are the statements where
you name a variable, constant, or procedure, and can also
specify a data type.
• Executable statements − these are the statements, which
initiate actions. These statements can call a method or
function, loop or branch through blocks of code or assign
values or expression to a variable or constant.
Public Sub ApplyFormat()
Dim limit As Integer = 33
Const pi As Decimal = 3.14
' Insert code to implement the procedure.
End Sub
• The first declaration is the Sub statement. Together with its
matching End Sub statement, it declares a procedure named
applyFormat. It also specifies that applyFormat is Public,
which means that any code that can refer to it can call it.

• The second declaration is the Const statement, which


declares the constant limit, specifying the Integer data type
and a value of 33.

• The third declaration is the Dim statement, which declares


the variable newLimit, specifying the Long data type and a
value of 3333333333.
Const Vs Dim
• A Dim allocates memory for a variable. It identifies a
specific data type. You may then use the variable within
the scope of the declaration to store and retrieve
values.
• A Const defines a constant. You also define the data
type and you define the constant's value. You cannot
change the value of a
constant.
• The Scope rules apply to the constant just as they do a
variable.
VB.NET operators
• An operator is a symbol that tells the compiler to perform
specific mathematical or logical manipulations. VB.Net is rich in
built-in operators and provides following types of commonly
used operators −
Arithmetic Operators
Comparison Operators
Logical/Bitwise Operators
Bit Shift Operators
Assignment Operators
Miscellaneous Operators
A = 2, B = 7
Operator Description Example
^ Raises one operand to the power of another B^A will give 49
+ Adds two operands A + B will give 9
- Subtracts second operand from the first A - B will give -5
* Multiplies both operands A * B will give 14
/ Divides one operand by another and returns a B / A will give 3.5
floating point result
\ Divides one operand by another and returns B \ A will give 3
an integer result
MOD Modulus Operator and remainder of after an B MOD A will give 1
integer division
Example

•Create a console program that


will print the sum of 10 and 20.
Module Module1
Sub Main()
Dim firstVal As Integer = 10
firstVal = 10
Dim secondVal As Integer
secondVal = 20
Dim difference As Integer
sum = firstVal + secondVal
Console.WriteLine(difference)
End Sub
End Module
Module Module1
Sub Main()
Dim firstVal, secondVal, sum As Integer
firsVal = 10
secondVal = 20
sum = firstVal + secondVal
Console.WriteLine(sum)
Console.ReadKey()
End Sub
End Module
Module Module1
Sub Main()
Console.WriteLine(10 Mod 20)
Console.ReadKey()
End Sub
End Module
Module Module1
Sub Main() Output:
Console.WriteLine(20 Mod 10) 0
Console.ReadKey()
End Sub
End Module
VB.NET input function

•ReadLine()
• The most commonly used input function is ReadLine. The
ReadLine Function reads a single line from the standard input
stream or the command line. Basically it reads all the
characters a user types until he presses enter.
Module Module1
Sub Main()
Dim result As String

Console.WriteLine(“Enter the string”)


result = Console.ReadLine()
Console.WriteLine(result)
Console.ReadKey()

End Sub
End Module
Exercises
1. Create a console program that will print the
difference of 10.24 and 6.05. Use three variables.
2. Create a console program that will print the product
of 10 and 20. Use the two variables.
3. Create a console program that will print the
remainder of 10 and 12 when divided.
4. Create a console program that will print the
quotient of 100 and 10. The output should be “The
quotient of 100 and 10 is __.”
•4. Create a console program that will print
the quotient of 100 and 10. The output
should be “The quotient of 100 and 10 is __.”

• Console.WriteLine(“The quotient of 100 and 10 is “ + ___)


• Console.WriteLine(“The quotient of 100 and 10 is “ & ___)
Quiz (30 minutes only)

•Create a console program that will


display the sum, difference,
product, quotient and remainder of
two input numbers at the same
time.
Comparison operators
Operator

< (Less than)

<= (Less than or equal to)

> (Greater than)

>= (Greater than or equal to)

= (Equal to)

<> (Not equal to)


Operators
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
= Equal to
<> Not equal to
Imports System
Module Comparison_Operator
Sub Main()
Dim x As Integer = 5
Dim y As Integer = 10

Console.WriteLine (" Program of Comparison Operator")


Console.WriteLine (x > y)
Console.WriteLine (x < y)
Console.WriteLine (x = y)
Console.WriteLine (x <> y)
Console.WriteLine (x >= y)
Console.WriteLine (x <= y)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module
•Write a program that will print True if
100 is greater than 50.

•Write a program that will print


True/False if 10 is equal, not equal,
greater than, less than, greater than or
equal to, less than or equal to 20 at
the same time.
Conditional statements
Statement Description
If ... Then statement An If...Then statement consists of a boolean expression
followed by one or more statements.
If...Then...Else statement An If...Then statement can be followed by an optional Else
statement, which executes when the boolean expression is
false.
nested If statements You can use one If or Else if statement inside
another If or Else if statement(s).
Select Case statement A Select Case statement allows a variable to be tested for
equality against a list of values.
nested Select Case statements You can use one select case statement inside another select
case statement(s).
The If...Else If...Else Statement
Module decisions
Sub Main()
Dim a As Integer = 100
If (a = 10) Then
Console.WriteLine("Value of a is 10") ‘
ElseIf (a = 20) Then
Console.WriteLine("Value of a is 20") ‘
ElseIf (a = 30) Then
Console.WriteLine("Value of a is 30")
Else
Console.WriteLine("None of the values is
matching")
End If
Console.ReadLine()
End Sub
End Module
•Create a console program that will
print “The numbers are equal” if the
two input numbers are equal, else
print “The numbers are not equal”.

•If – else statement


1. Create a program that will print whether
True or False if the first input value is
greater than the second input value.
2. Create a program that will print wether
True or False if the first input value is
greater than, less than, greater than or
equal, less than or equal, equal, not equal
to the second input number at the same
time.
Windows Form Application
Performance Task: ARITHMETIC
OPERATIONS
• Create a Windows Form Application that will perform
addition, subtraction, multiplication, division, and modulus.
Drag five (5) labels, two (2) Text Boxes, and five (5) Button
controls from the Toolbox to the Windows form and follow
the arrangement for the positioning of each control. Name
your Windows Form App as
ArithmeticCalculator_____(section & group#).
How to publish project in VB.NET
• Project • Uncheck use deploy
• Properties • Publishing folder
• Publish Location
• Prerequisites • This PC, Data (D)
• Uncheck create set up • Publish now
• Options • Applications files
• Deployment

You might also like