L4_NumericString

L4_NumericString - Chapter 4 How t work with H to k ith...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 4 How to work with umeric and string data numeric and string data Murach’s Visual Basic 2005, C4 © 2006, Mike Murach & Associates, Inc. Slide 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline • VB 2005 data types • How to work with numeric data • How to work with string data 2
Background image of page 2
ata Types Data Types TYPE STORES MEMORY VALUES Boolean Logical 2 bytes True or False Byte Unsigned int 1 byte 0 to 255 Short Integer 2 bytes -32,768 to 32767 Integer Integer 4 bytes ± 2 billion Long Integer 8 bytes ± 9E+18 ingle loating oint bytes E 5 to E38 Single Floating-point 4 bytes ± 1E-45 to ± 3E38 Double Floating-point 8 bytes ± 5E-324 to ± 1.8E308 Decimal “Currency” 16 bytes ± 1E-27 to ± 7.9E28 Doubles are often used for scientific calculation for higher precision 3 Decimals are often used to represent currency
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data Types TYPE STORES MEMORY VALUES tring ext (Unicode) 0 bytes + to 2E9 characters String Text (Unicode) 10 bytes + 0 to 2E9 characters 2 * string length Date Date & 8 bytes 1/1/1 to 12/31/9999 Time info Object Any object 4 bytes Any type reference 4
Background image of page 4
How to declare and initialize a variable Syntax Dim variableName As type [ = expression] xamples Examples Dim counter As Integer Dim numberOfBytes As Long = 20000 Dim price As Double = 14.95 p ce s oub e .95 Dim interestRate As Single = 8.125 Dim total As Decimal = 24218.1928D ' D indicates a Decimal value Dim letter As Char = "A"C ' C indicates a Char value Dim valid As Boolean = True Dim x, y As Integer ' declare 2 variables with 1 statement declare 2 variables with 1 statement Dim i As Integer, d As Decimal ' declare 2 variables with different types Murach’s Visual Basic 2005, C4 © 2006, Mike Murach & Associates, Inc. Slide 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ow to declare and initialize a constant How to declare and initialize a constant Syntax Const ConstantName As type = expression Examples Const DaysInNovember As Integer = 30 Const SalesTax As Decimal = .075D Murach’s Visual Basic 2005, C4 © 2006, Mike Murach & Associates, Inc. Slide 6
Background image of page 6
Naming conventions g Start the names of variables with a lowercase letter, and capitalize the first letter of each word after the first word. This is known as camel notation . Capitalize the first letter of each word of a constant name. Assign meaningful names that will be easily remembered as you de code. Murach’s Visual Basic 2005, C4 © 2006, Mike Murach & Associates, Inc. Slide 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Variable Naming Conventions • A variable name – should begin with a letter, followed by more letters or digits – can’t contain embedded periods or other special unctuation symbols (e g space) punctuation symbols (e.g., space) – must not exceed 255 characters – must be unique within the variable’s scope • Variable names in VB2005 are case-insensitive 8
Background image of page 8
Suggested Naming Conventions • Favor readability over brevity • Do not use any acronyms that are not widely accepted, and then only when necessary • Do not use underscores, hyphens, or any other non-alphanumeric characters 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scope of Variables • Each variable has a scope , which is the section of the application that can see and manipulate the variable variable DOES NOT exist outside of its A variable DOES NOT exist outside of its scope 10
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 46

L4_NumericString - Chapter 4 How t work with H to k ith...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online