200 likes | 341 Views
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.
E N D
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. Kalbunna 2. Hang sreyleak • 5. Horphallin • 3. Kong chanpanith 6. Mitkosal
contents 1. Definition. • 2. User-Defined Constants. • 3. Built-In constants. • 4. Q & A. EXIT
1. DEFINITION Constant is a meaningful name that takes the place of DataTypethat 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. DEFINITION Why 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. • There are two types of constant: • User-Defined Constants • Built-In Constants Home
2. User-Defined • 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 ConstNameAsType = 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 . Home
Option Strict • Example: • Option Strict Off • Public Const DaysInYear = 365 • Private Const WorkDays = 250 • Option Strict On • Public Const DaysInYear As Integer = 365 • Private Const WorkDays As Integer = 250 Home
Constant And Literal Data Type • Example: Home
Build-in Constants • (Intrinsic constants) • The specific built-in constants are available at all time that use with Functionor Method,andProperty . • Visual Basic provides a number of predefined constants for developers for : • Use with Function Or Method. • Use with Property of Controls. Home
Build-in Constants • When you use it with Function or Method , you can use the following constants in you code in place of the actual value. • ControlCharsMember : Home
Build-in Constants Ex: Using member of ControlChars MsgBox (“Me”& ControlChars.Newline &”You”) Result: Me You Home
Build-in Constants - 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 Home
Build-in Constants 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 Sub End End Sub Home
Build-in Constants Use with Property of controls Ex: Label1.text.foreColor= Color.Blue Or we can set it at Design time in Property Window. Home
Build-in Constants • 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 ] • EnumEnumerationName[AsType] • MemberList • End Enum Home
Build-in Constants • Constant & Enumeration: Ex: MsgBoxStyle.OkOnly Enum-name member Ex: ControlChars Home
References • VB.Net Language in a NutShell • VB.Net Language Step by Step • MSDN Library VB.Net 2008
Thank you for your attention Q and a Home