Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore...

41
Introduction to VB6 Introduction to VB6 PPCC Course PPCC Course Winter 2004 Winter 2004 Week 0 – Background Week 0 – Background Information Information Copyright ©2004, Tore Bostrup Copyright ©2004, Tore Bostrup

Transcript of Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore...

Page 1: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

Introduction to VB6Introduction to VB6

PPCC CoursePPCC Course

Winter 2004Winter 2004

Week 0 – Background InformationWeek 0 – Background Information

Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

Page 2: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

22

Course Outline, Week 0Course Outline, Week 0Background InformationBackground Information– Computer Science BasicsComputer Science Basics

Binary NumbersBinary NumbersData TypesData TypesInstructions and DataInstructions and DataCompilers and InterpretersCompilers and InterpretersVariables and AssignmentsVariables and Assignments

– Object Orientation BasicsObject Orientation BasicsWhat is an objectWhat is an objectVisual Basic built-in “Objects”Visual Basic built-in “Objects”

– Windows Environment BasicsWindows Environment BasicsMessage-based and Event-Driven ArchitectureMessage-based and Event-Driven Architecture

– The different VB’s (VB, VBA, VBScript)The different VB’s (VB, VBA, VBScript)

Page 3: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

33

Binary NumbersBinary NumbersFrom the earliest days of computers, they From the earliest days of computers, they have been built with technology that have been built with technology that provides two states:provides two states:– ONON– OFFOFFThis means that all the data is represented This means that all the data is represented by a series of 0’s and 1’sby a series of 0’s and 1’sLogically, a 0 is OFF and a 1 is ONLogically, a 0 is OFF and a 1 is ONPhysically, that is not always the casePhysically, that is not always the caseWe call the unit that holds a 0 or a 1 a BIT.We call the unit that holds a 0 or a 1 a BIT.

Page 4: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

44

Binary NumbersBinary NumbersComputer memory is organized in groups Computer memory is organized in groups of bits, often called a WORD.of bits, often called a WORD.The computer architecture defines the The computer architecture defines the WORD length. Most of today’s PC’s have a WORD length. Most of today’s PC’s have a word length of 32 bits.word length of 32 bits.Both Intel and AMD have 64-bit Both Intel and AMD have 64-bit architectures in production, but very few architectures in production, but very few vendors have started to offer these in vendors have started to offer these in anything other than server class anything other than server class machines.machines.

Page 5: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

55

Binary NumbersBinary NumbersSo what can we store in a group of bits?So what can we store in a group of bits?– One bit:One bit:

0 or 1, i.e. two values0 or 1, i.e. two values– Two bits:Two bits:

00, 01, 10, 11 (0, 1, 2, 3), i.e. four values00, 01, 10, 11 (0, 1, 2, 3), i.e. four values– Three bits:Three bits:

000, 001, 010, 011, 100, 101, 110, 111000, 001, 010, 011, 100, 101, 110, 111(0, 1, 2, 3, 4, 5, 6, 7), i.e. eight values(0, 1, 2, 3, 4, 5, 6, 7), i.e. eight values

– Generally:Generally:n bits can hold 2^n values, 0 to 2^n – 1n bits can hold 2^n values, 0 to 2^n – 1

– Get used to the 2^n values:Get used to the 2^n values:2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 655368192, 16384, 32768, 65536

Page 6: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

66

Binary NumbersBinary NumbersDecoding a binary value:Decoding a binary value:– 0101111001011110– Most significant bit is rightmost (of Most significant bit is rightmost (of

course)course)– Starting with the least significant bit, Starting with the least significant bit,

and proceeding towards the most and proceeding towards the most significant bit, we get:significant bit, we get:

0*2^0 + 1*2^1 + 1*2^2 + 1*2^3 + 1*2^4 0*2^0 + 1*2^1 + 1*2^2 + 1*2^3 + 1*2^4 + 0*2^5 + 1*2^6 + 0*2^7+ 0*2^5 + 1*2^6 + 0*2^7Or 0+2+4+8+16+0+64+0 = 94Or 0+2+4+8+16+0+64+0 = 94

Page 7: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

77

Binary NumbersBinary Numbers

Regardless of the WORD length, it is Regardless of the WORD length, it is often useful to deal with groups of often useful to deal with groups of eight bits. This is sufficient to eight bits. This is sufficient to represent all western languages’ represent all western languages’ common symbols.common symbols.

A group of 8 bits is called a BYTE.A group of 8 bits is called a BYTE.

Page 8: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

88

Binary NumbersBinary NumbersA BYTE:A BYTE:– 8 bits:8 bits:

00000000 to 1111111100000000 to 111111110 through 255 (2^8 – 1)0 through 255 (2^8 – 1)

ASCIIASCII– ASCII (American Standard Coding for Information ASCII (American Standard Coding for Information

Interchange) is a standard for how to map byte values to Interchange) is a standard for how to map byte values to characters.characters.

ASCII actually only defines the first 128 valuesASCII actually only defines the first 128 values

ANSIANSI– American National Standards InstituteAmerican National Standards Institute

One of many ANSI standards are for character encoding One of many ANSI standards are for character encoding and is used by Windows. Often confused with ASCII.and is used by Windows. Often confused with ASCII.

Page 9: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

99

ASCII ChartsASCII Charts

The following ASCII chart is fromThe following ASCII chart is from– http://www.cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/ascii.htmhttp://www.cdrummond.qc.ca/cegep/informat/Professeurs/Alain/files/ascii.htm

The ASCII-II chart on that page does The ASCII-II chart on that page does not match the Windows ANSI not match the Windows ANSI character codes, so disregard it…character codes, so disregard it…

The ANSI Chart is fromThe ANSI Chart is from– http://h18009.www1.hp.com/fortran/docs/vf-html/lref/pg9ansi2.http://h18009.www1.hp.com/fortran/docs/vf-html/lref/pg9ansi2.htmhtm

Page 10: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1010

ASCII ChartASCII Chart

Page 11: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1111

ANSI Character Codes ChartANSI Character Codes Chart

Page 12: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1212

Binary NumbersBinary NumbersBeyond ASCIIBeyond ASCII– ANSI standards have expanded on the ASCII ANSI standards have expanded on the ASCII

codes to include multiple languages, etc.codes to include multiple languages, etc.– 8 bits is not sufficient to accommodate several 8 bits is not sufficient to accommodate several

Far East languages. A 16-bit character Far East languages. A 16-bit character encoding known as UNICODE is used to encoding known as UNICODE is used to accommodate these languages.accommodate these languages.

– Starting with Windows 2000, text files are Starting with Windows 2000, text files are stored as UNICODE characters by default.stored as UNICODE characters by default.

– Unicode characters for western languages tend Unicode characters for western languages tend to consist of a byte containing a zero value, to consist of a byte containing a zero value, and a byte containing the ASCII/ANSI value.and a byte containing the ASCII/ANSI value.

Page 13: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1313

Binary NumbersBinary NumbersBecause binary numbers quickly get lots of Because binary numbers quickly get lots of digits, it is common to use Hexadecimal digits, it is common to use Hexadecimal (Hex for short) values. That means that (Hex for short) values. That means that instead of using powers of 10, we use instead of using powers of 10, we use powers of 16, with the digits 0 through 9 powers of 16, with the digits 0 through 9 and A (=10) through F (=15).and A (=10) through F (=15).

One hex digit is represented by four bits, One hex digit is represented by four bits, and a Byte value can be shown as two hex and a Byte value can be shown as two hex digits (00 – FF).digits (00 – FF).

Page 14: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1414

Binary NumbersBinary Numbers

Negative NumbersNegative Numbers– In order to allow negative values, the In order to allow negative values, the

first bit (most significant) is interpreted first bit (most significant) is interpreted as a “sign bit”.as a “sign bit”.

– 0 means the number is positive, 0 means the number is positive, 1 means it is negative.1 means it is negative.

– Instead of interpreting the remaining Instead of interpreting the remaining bits the same, negative numbers are bits the same, negative numbers are interpreted by INVERTING each bit.interpreted by INVERTING each bit.

Page 15: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1515

Negative NumbersNegative Numbers

One’s ComplementOne’s Complement– By only inverting the bits, we get two By only inverting the bits, we get two

different values for 0 – a positive 0 different values for 0 – a positive 0 (0000) and a negative 0 (1111).(0000) and a negative 0 (1111).

– This is known as One’s Complement.This is known as One’s Complement.

Page 16: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1616

Negative NumbersNegative Numbers

Two’s ComplementTwo’s Complement– To avoid this duplicity, we first subtract To avoid this duplicity, we first subtract

1 from the POSITIVE value to be 1 from the POSITIVE value to be inverted, and then invert the bits.inverted, and then invert the bits.

– This results in -1 being represented as:This results in -1 being represented as:00010001

Subtract 1: 0000Subtract 1: 0000

Invert: 1111Invert: 1111

– This is called Two’s ComplementThis is called Two’s Complement

Page 17: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1717

Negative NumbersNegative NumbersTwo’s ComplementTwo’s Complement– This allows the “largest” negative This allows the “largest” negative

numbers to be one “larger” than the numbers to be one “larger” than the largest positive number:largest positive number:

0, Positive: 1 to 2^(n-1) – 10, Positive: 1 to 2^(n-1) – 1Negative: -1 to –(2^(n-1))Negative: -1 to –(2^(n-1))

– A 16-bit signed value can contain the A 16-bit signed value can contain the following values:following values:

0 to 327670 to 32767-1 to -32768-1 to -32768

Page 18: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1818

Binary Numbers and VB6Binary Numbers and VB6

Whole Number values are kept in 16-Whole Number values are kept in 16-bit or 32-bit VARIABLES.bit or 32-bit VARIABLES.– VB6: VB6:

Integer is 16-bitInteger is 16-bit

Long is 32-bitLong is 32-bit

VB6 Byte variables are NOT SIGNED.VB6 Byte variables are NOT SIGNED.

Page 19: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

1919

Binary NumbersBinary Numbers

Other types of NumbersOther types of Numbers– Floating PointFloating Point

One group of bits hold the significant digits One group of bits hold the significant digits (Mantissa)(Mantissa)

Another group of bits holds the ExponentAnother group of bits holds the Exponent

Floating point values are NOT ACCURATE.Floating point values are NOT ACCURATE.

After simple arithmetic, a value that may After simple arithmetic, a value that may look like for example 0.45 may actually be look like for example 0.45 may actually be 0.4499…997, so testing for equal to 0.45 0.4499…997, so testing for equal to 0.45 WILL FAIL!WILL FAIL!

Page 20: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2020

Binary NumbersBinary Numbers

Other types of NumbersOther types of Numbers– Fixed PrecisionFixed Precision

Representation can varyRepresentation can vary

VB6 has Decimal and Currency types which VB6 has Decimal and Currency types which are fixed precision.are fixed precision.

Rounding may still be an issue, unless the Rounding may still be an issue, unless the full precision is used.full precision is used.

VB6’s Currency type has FOUR decimals, so VB6’s Currency type has FOUR decimals, so for example $1 / 3 is $0.3333, not $0.33for example $1 / 3 is $0.3333, not $0.33

Page 21: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2121

Binary NumbersBinary Numbers

DatesDates– Dates are usually represented as double Dates are usually represented as double

precision floating point values, with the precision floating point values, with the integer portion representing the number integer portion representing the number of days since some predefined “start of days since some predefined “start date”, and the fraction as a fraction of a date”, and the fraction as a fraction of a 24 hr period.24 hr period.

– VB6 uses the start of (midnight) VB6 uses the start of (midnight) 12/30/1899 as its calendar “start date”.12/30/1899 as its calendar “start date”.

Page 22: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2222

VB6 Data TypesVB6 Data TypesNumeric Data TypesNumeric Data Types– Boolean: True or False (-1 and 0)Boolean: True or False (-1 and 0)– Byte: 8-bit unsigned whole numberByte: 8-bit unsigned whole number– Integer: 16-bit signed whole numberInteger: 16-bit signed whole number– Long: 32-bit signed whole numberLong: 32-bit signed whole number– Decimal: Up to 29 (decimal) digits (total), maximum 28 Decimal: Up to 29 (decimal) digits (total), maximum 28

digits to the right of the decimal pointdigits to the right of the decimal point– Currency: Fixed Point (four decimals), - value range is Currency: Fixed Point (four decimals), - value range is

-922,337,203,685,477.5808 to -922,337,203,685,477.5808 to 922,337,203,685,477.5807922,337,203,685,477.5807

– Single: Single Precision floating pointSingle: Single Precision floating point– Double: Double Precision floating pointDouble: Double Precision floating point

Page 23: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2323

VB6 Data TypesVB6 Data TypesOtherOther– DateDate

Contains a date and time value stored as a Double Contains a date and time value stored as a Double with offset from midnight 12/30/1899with offset from midnight 12/30/1899

– StringStringVariable or fixed length text stringsVariable or fixed length text strings

– ObjectObjectReference to an instantiated objectReference to an instantiated object

– VariantVariantThe “chameleon” variable – it can be any type of The “chameleon” variable – it can be any type of valuevalue

Page 24: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2424

Instructions and DataInstructions and Data

The CPUThe CPU– The CPU contains several REGISTERS The CPU contains several REGISTERS

and knows what to do for certain simple and knows what to do for certain simple INSTRUCTIONSINSTRUCTIONS

– The CPU knows how to access a memory The CPU knows how to access a memory LOCATION by an ADDRESSLOCATION by an ADDRESS

– Many/most CPU operations involve one Many/most CPU operations involve one or more REGISTERS and/or one memory or more REGISTERS and/or one memory LOCATIONLOCATION

Page 25: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2525

Instructions and DataInstructions and DataCPU InstructionsCPU Instructions– Typical instructions would be:Typical instructions would be:

Load contents of memory location X into register YLoad contents of memory location X into register Y

Add contents of location Z to register YAdd contents of location Z to register Y

Jump to location AJump to location A

Jump to location B if register M is zeroJump to location B if register M is zero

Call location CCall location C– Call is a JUMP where the NEXT location is pushed to a Call is a JUMP where the NEXT location is pushed to a

stackstack

A Stack is a Last In First Out (LIFO) list maintained A Stack is a Last In First Out (LIFO) list maintained by a separate registerby a separate register

Page 26: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2626

Instructions and DataInstructions and DataAt the lowest level, there is no real At the lowest level, there is no real difference between instructions and difference between instructions and code.code.It becomes code when the CPU is It becomes code when the CPU is asked to execute the content of a asked to execute the content of a memory location as an instruction.memory location as an instruction.In high level languages, this is In high level languages, this is usually separated outside the usually separated outside the developers’ control (*).developers’ control (*).

Page 27: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2727

Instructions and DataInstructions and DataThe instructions that the CPU understands The instructions that the CPU understands are called MACHINE INSTRUCTIONS and are called MACHINE INSTRUCTIONS and are simply WORDS containing certain bit are simply WORDS containing certain bit patterns.patterns.Many instructions include a memory Many instructions include a memory reference portion, usually a relative offset reference portion, usually a relative offset to the location of the instruction itselfto the location of the instruction itselfIn order to access a large amount of In order to access a large amount of memory, memory addressing is INDIRECT, memory, memory addressing is INDIRECT, i.e. the memory reference portion i.e. the memory reference portion references a location that contains a references a location that contains a memory reference.memory reference.

Page 28: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2828

Compilers and InterpretersCompilers and InterpretersIn order to make it easier to write In order to make it easier to write instructions for the CPU, mnemonic codes instructions for the CPU, mnemonic codes were assigned to the various MACHINE were assigned to the various MACHINE INSTRUCTIONS, and an ASSEMBLER would INSTRUCTIONS, and an ASSEMBLER would translate these mnemonic codes to translate these mnemonic codes to MACHINE instructions.MACHINE instructions.An ASSEMBLY instruction example An ASSEMBLY instruction example (fictitious)(fictitious)JNZ -7 (Jump to address of this instruction -7 if JNZ -7 (Jump to address of this instruction -7 if

register A is not Zero). This could be used to register A is not Zero). This could be used to construct a loop.construct a loop.

Page 29: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

2929

Compilers and InterpretersCompilers and InterpretersWriting complex applications using only Writing complex applications using only ASSEMBLY instructions easily becomes a ASSEMBLY instructions easily becomes a tedious and major undertaking (one of tedious and major undertaking (one of very few exceptions: very few exceptions: http://grc.comhttp://grc.com))

Higher level languages translate more Higher level languages translate more complex instructions into machine complex instructions into machine instructionsinstructions– On-the-fly: InterpretersOn-the-fly: Interpreters– Before you can execute: CompilersBefore you can execute: Compilers

Page 30: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3030

Compilers and InterpretersCompilers and Interpreters

VB6 uses a hybrid solution:VB6 uses a hybrid solution:– In the IDE, it works in an Interpretative In the IDE, it works in an Interpretative

manner, but when producing an Exe, it manner, but when producing an Exe, it compiles the code. The compiled code compiles the code. The compiled code still relies very heavily on the (relatively still relies very heavily on the (relatively large) runtime system.large) runtime system.

Page 31: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3131

Variables and AssignmentsVariables and Assignments

Higher level languages introduces named Higher level languages introduces named Variables. Each Variable (usually) represents one Variables. Each Variable (usually) represents one or more memory locations (words).or more memory locations (words).The TYPE of variable determines how the memory The TYPE of variable determines how the memory locations are interpreted.locations are interpreted.In order to define where the data for a variable is In order to define where the data for a variable is stored, and what type it is, we need to DECLARE stored, and what type it is, we need to DECLARE the variable.the variable.Dim x As StringDim x As String

Variables are given values by ASSIGNMENT Variables are given values by ASSIGNMENT statementsstatementsx = “Welcome to PPCC Introduction to VB6”x = “Welcome to PPCC Introduction to VB6”

Page 32: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3232

Variables and AssignmentsVariables and AssignmentsForget Equations – in VB, something like x Forget Equations – in VB, something like x = y – 6 is not one of two equations require = y – 6 is not one of two equations require to solve for x and y… it means the variable to solve for x and y… it means the variable x will be assigned the value of variable y x will be assigned the value of variable y minus 6.minus 6.The part to the right of the equal sign in an The part to the right of the equal sign in an assignment statement is called an assignment statement is called an EXPRESSION.EXPRESSION.You can use the value of the variable that You can use the value of the variable that you are assigning to in the expression as you are assigning to in the expression as well:well:x = x - 6 means x(after) = x(before) - 6x = x - 6 means x(after) = x(before) - 6

Page 33: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3333

Object Orientation BasicsObject Orientation Basics

An OBJECT is a logical component that consists of An OBJECT is a logical component that consists of code as well as data.code as well as data.

Typical for an object is that it ENCAPSULATES the Typical for an object is that it ENCAPSULATES the data, meaning you can only access its data data, meaning you can only access its data through properties and methods that it exposes.through properties and methods that it exposes.– This allows it to control how the data is presented, and This allows it to control how the data is presented, and

what you can do to it.what you can do to it.

Page 34: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3434

What is an objectWhat is an object

Consider a Word document. If you were to open a Consider a Word document. If you were to open a .doc file with NotePad, you would see a lot of .doc file with NotePad, you would see a lot of gibberish. If you made changes to it, or even just gibberish. If you made changes to it, or even just saved it in NotePad, chances are you would have saved it in NotePad, chances are you would have a problem opening it back up in Word!a problem opening it back up in Word!

The “Document” is like an Object – Word is the The “Document” is like an Object – Word is the code and the file (after it is read into Word) is the code and the file (after it is read into Word) is the data.data.

Page 35: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3535

Visual Basic built-in “Objects”Visual Basic built-in “Objects”

Forms and Controls are ObjectsForms and Controls are Objects

Database access uses ADO ObjectsDatabase access uses ADO Objects

A Collection (a VB6 Data Type) is an ObjectA Collection (a VB6 Data Type) is an Object

Page 36: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3636

Windows Environment BasicsWindows Environment Basics

Windows is the operating system that controls the Windows is the operating system that controls the execution of programs and their access to execution of programs and their access to resources on the system.resources on the system.

Windows provides an Application Programming Windows provides an Application Programming Interface (API), allowing most applications to Interface (API), allowing most applications to achieve most things that Windows itself can do.achieve most things that Windows itself can do.

Windows is built on passing MESSAGES between Windows is built on passing MESSAGES between programs (or objects).programs (or objects).

The visual aspects of Windows (its windows, The visual aspects of Windows (its windows, controls, etc.) communicate primarily through controls, etc.) communicate primarily through messages that generate program EVENTS.messages that generate program EVENTS.

Page 37: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3737

Message-based and Event-DrivenMessage-based and Event-Driven

Applications typically react to mouse clicks, Applications typically react to mouse clicks, mouse movements, keyboard input, etc.mouse movements, keyboard input, etc.

Code in a VB application gets run when the Code in a VB application gets run when the EVENT HANDLER they belong to is executed as a EVENT HANDLER they belong to is executed as a result of an EVENT.result of an EVENT.

Page 38: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3838

The different VB’s (VB, VBA, VBScript)The different VB’s (VB, VBA, VBScript)

VB6 is a many-headed “monster”.VB6 is a many-headed “monster”.– There is VBThere is VB– There is VBAThere is VBA– There is VBScriptThere is VBScript

Page 39: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

3939

The different VB’s (VB, VBA, VBScript)The different VB’s (VB, VBA, VBScript)

VBVB– This is what you develop in the VB IDE and compile into This is what you develop in the VB IDE and compile into

an executable through the Microsoft Visual Basic an executable through the Microsoft Visual Basic application.application.

Page 40: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

4040

The different VB’s (VB, VBA, VBScript)The different VB’s (VB, VBA, VBScript)

There is VBAThere is VBA– This is the language supported by many/most Microsoft This is the language supported by many/most Microsoft

applications and many third party apps.applications and many third party apps.– VBA code is developed inside another application, and VBA code is developed inside another application, and

runs in the context of this application.runs in the context of this application.– VB and VBA are quite similar – in fact VB includes the VB and VBA are quite similar – in fact VB includes the

VBA engine…VBA engine…

Page 41: Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.

1/27/20041/27/2004 PPCC - Introduction to VB6 - Week 0PPCC - Introduction to VB6 - Week 0Copyright ©2004, Tore BostrupCopyright ©2004, Tore Bostrup

4141

The different VB’s (VB, VBA, VBScript)The different VB’s (VB, VBA, VBScript)

There is VBScriptThere is VBScript– This is a simplified VB that is interpreted (no compiler This is a simplified VB that is interpreted (no compiler

available).available).– VBScript can be executed directly from Windows VBScript can be executed directly from Windows

Explorer or from the command line.Explorer or from the command line.– VBScript can be used to develop Active Server Pages – VBScript can be used to develop Active Server Pages –

web pages that can access server side resources.web pages that can access server side resources.– VBScript provides a subset of VB statements and VBScript provides a subset of VB statements and

functions, and does not include forms, etc.functions, and does not include forms, etc.– VBScript can not access API functions directly.VBScript can not access API functions directly.