royal university of phnom penh

20
Royal university of Phnom penh Subject : vb.net Teacher : kean tak Title : constant Group member 1. Ty sovisal 2. Hang sreyleak 3. Kong chanpanith 4. Kal bunna 5. Hor phallin 6. Mit kosal Royal university of Phnom penh Subject : vb.net Teacher : kean tak Title : constant Group member

Upload: hiroko

Post on 15-Feb-2016

45 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: Royal university of Phnom penh

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

Page 2: Royal university of Phnom penh

contents

1. Definition.

2. User-Defined Constants.

3. Built-In constants.

EXIT

4. Q & A.

Page 3: Royal university of Phnom penh

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

Page 4: Royal university of Phnom penh

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

Page 5: Royal university of Phnom penh

• 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

Page 6: Royal university of Phnom penh

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

Page 7: Royal university of Phnom penh

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

Page 8: Royal university of Phnom penh

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

Page 9: Royal university of Phnom penh

Constant And Literal Data Type

Home

Page 10: Royal university of Phnom penh

Constant And Literal Data TypeExample:

Home

Page 11: Royal university of Phnom penh

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.

Page 12: Royal university of Phnom penh

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

Page 13: Royal university of Phnom penh

3. Build-in Constants

Ex: Using member of ControlChars

MsgBox (“Me”& ControlChars.Newline &”You”)

Result: MeYou

Home

Page 14: Royal university of Phnom penh

- 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

Page 15: Royal university of Phnom penh

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

Page 16: Royal university of Phnom penh

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

Page 17: Royal university of Phnom penh

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

Page 18: Royal university of Phnom penh

• Constant & Enumeration:Ex:MsgBoxStyle.OkOnly

Enum-name memberEx: ControlChars

3. Build-in Constants

Home

Page 19: Royal university of Phnom penh

–VB.Net Language in a NutShell–VB.Net Language Step by Step– MSDN Library VB.Net 2008

References

Page 20: Royal university of Phnom penh

Q aAND

Thank you for yourattention

Home