royal university of phnom penh
DESCRIPTION
Royal university of Phnom penh. Royal university of Phnom penh. Subject: vb.net. Subject: vb.net. Teacher: kean tak. Teacher: kean tak. Title: constant. Title: constant. Group member. Group member. 1. Ty sovisal. 4. Kal bunna. 2. Hang sreyleak. 5. Hor phallin. - PowerPoint PPT PresentationTRANSCRIPT
Royal university of Phnom penh
Subject : vb.netTeacher : kean takTitle : constantGroup member
1. Ty sovisal2. Hang sreyleak3. Kong chanpanith
4. Kal bunna5. Hor phallin6. Mit kosal
Royal university of Phnom penh
Subject : vb.netTeacher : kean takTitle : constantGroup member
contents
1. Definition.
2. User-Defined Constants.
3. Built-In constants.
EXIT
4. Q & A.
1.DEFINITIONConstant is a meaningful name that takes the place
of DataType that does not change.
Why we create Constant ? We create constants for the following reason: To store the value as the name implies.
Ex: Public Const PI as Double = 3.14
Readability of your code and make it easier to maintain.
Home
1.DEFINITIONWhy we create Constant ? We create constants for the following reason:
Use in code to contain value that repeat or dependent on certain value.
Use to printing or Display.
Home
There are two types of constant:
User-Defined Constants Built-In Constants
• Symbolic or user-defined constants , which enable you to use a meaningful name in place of a number or string . Symbolic Constants , which you can create by using the const statement.
Home
2. User-Defined
Syntax 1:
[ accessmodifier ] Const ConstName AsType = ConstValue
Ex: Public Const Five as Integer = 5
Syntax 2:
[ accessmodifier ] Const ConstantsList
Ex: Private Const Stname as String = “Net”, Age as Integer = 18 Home
2. User-Defined
Accessmodifier : Optional , We can use one of the following keyword such as (Private) , Public , Friend , Protected ,Protected Friend .
ConstName : Required , The name of constant that has rule as Variable’s name.
Type : Optional if Option Strict off , Data Type of Constants .
ConstValue : Required ,Can Numeric or String Data Type .
2. User-Defined
Home
Option StrictExample: Option Strict Off
Public Const DaysInYear = 365Private Const WorkDays = 250
Option Strict On Public Const DaysInYear As Integer = 365 Private Const WorkDays As Integer = 250
Home
Constant And Literal Data Type
Home
Constant And Literal Data TypeExample:
Home
3. Build-in Constants(Intrinsic constants)
Home
The specific built-in constants are available at
all time that use with Function or Method, and
Property .
Visual Basic provides a number of predefined
constants for developers for :
Use with Function Or Method.
Use with Property of Controls.
3. Build-in ConstantsWhen you use it with Function or Method , you can use the following constants in you code in place of the actual value.
ControlChars Member :Member Constants Equivalent Description
CrLf VbCrLf Chr(13)+Chr(10) Carriage-return/linefeed character combination.
Cr vbCr Chr(13) Carriage-return character.Lf vbLf Chr(10) Linefeed character.NewLine vbNewLine Chr(13) +Chr(10) Newline character. NullChar vbNullChar Chr(0) Character having value 0.Tab vbTab Chr(9) Tab character.
Home
3. Build-in Constants
Ex: Using member of ControlChars
MsgBox (“Me”& ControlChars.Newline &”You”)
Result: MeYou
Home
- Button Display Constants:Ex: MsgBoxStyle.OkOnly Value = 0- Icon Display Constants:Ex: MsgBoxStyle.Exclamation Value = 48- Return Value Constants:Ex: MsgBoxResult.Ok Value = 1
- Data Type (Integer, Double….) Have the exact value
3. Build-in Constants
Home
Private Sub cmdClose_Click()Dim Y As Integer
Y=MsgBox(“Do you want to close?” , MsgBoxStyle.YesNo,”Close Form”)
If Y=MsgBoxResult.No Then Exit SubEnd
End Sub
3. Build-in Constants
Home
Use with Property of controls
Ex: Label1.text.foreColor= Color.BlueOr we can set it at Design time in Property
Window.
3. Build-in Constants
Home
Constant & Enumeration:
Enumeration provide a sets of relate constants , and to
associate constant value with name.
When the statement refer to a member of an
enumeration automatically display a list of all member.Syntax 1:
[ accessmodifier ] Enum EnumerationName [AsType]
MemberListEnd Enum
3. Build-in Constants
Home
• Constant & Enumeration:Ex:MsgBoxStyle.OkOnly
Enum-name memberEx: ControlChars
3. Build-in Constants
Home
–VB.Net Language in a NutShell–VB.Net Language Step by Step– MSDN Library VB.Net 2008
References
Q aAND
Thank you for yourattention
Home