1 / 20

Royal university of Phnom penh

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.

hiroko
Download Presentation

Royal university of Phnom penh

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. contents 1. Definition. • 2. User-Defined Constants. • 3. Built-In constants. • 4. Q & A. EXIT

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. Constant And Literal Data Type Home

  10. Constant And Literal Data Type • Example: Home

  11. 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

  12. 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

  13. Build-in Constants Ex: Using member of ControlChars MsgBox (“Me”& ControlChars.Newline &”You”) Result: Me You Home

  14. 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

  15. 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

  16. 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

  17. 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

  18. Build-in Constants • Constant & Enumeration: Ex: MsgBoxStyle.OkOnly Enum-name member Ex: ControlChars Home

  19. References • VB.Net Language in a NutShell • VB.Net Language Step by Step • MSDN Library VB.Net 2008

  20. Thank you for your attention Q and a Home

More Related