visual basic 6 (vb6) data types

Upload: joshdax2

Post on 14-Apr-2018

237 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    1/16

    Visual Basic 6 (VB6) Data Types,Modules and Operators

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    2/16

    Visual Basic uses buildingblocks such as Variables,

    Data Types, Procedures,Functions and Control

    Structures in its programmingenvironment.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    3/16

    Modules

    Code in Visual Basic is stored in theform of modules. The three kind ofmodules are Form Modules,Standard Modules and ClassModules.

    A simple application may contain a

    single Form, and the code residesin that Form module itself. As theapplication grows, additional Forms

    are added and there may be a

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    4/16

    Modules To avoid the duplication of code, a

    separate module containing a procedureis created that implements the common

    code. This is a standard Module. Class module (.CLS filename extension)

    are the foundation of the object orientedprogramming in Visual Basic.

    New objects can be created by writingcode in class modules.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    5/16

    Each module can contain:

    Declarations : May includeconstant, type, variable and

    DLL procedure declarations.Procedures : A sub function,

    or property procedure thatcontain pieces of code thatcan be executed as a unit.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    6/16

    These are the rules to follow when naming elements inVB - variables, constants, controls, procedures, and so

    on:

    A name must begin with a letter.

    May be as much as 255 characters long(but don't forget that somebody has to

    type the stuff!). Must not contain a space or an

    embedded period or type-declaration

    characters used to specify a data type;these are ! # % $ & @

    Must not be a reserved word (that is part

    of the code, like Option, for example)

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    7/16

    The dash, although legal, should beavoided because it may beconfused with the minus sign.Instead of First-name useFirst_name or FirstName.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    8/16

    Data types in Visual Basic 6

    By default Visual Basic variables are ofvariant data types. The variant data typecan store numeric, date/time or string

    data. When a variable is declared, a data type

    is supplied for it that determines the kindof data they can store.

    The fundamental data types in VisualBasic including variant are integer, long,single, double, string, currency, byte and

    boolean.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    9/16

    Numeric

    Byte

    Store integer values in the range of 0 -255

    IntegerStore integer values in the range of (-

    32,768) - (+ 32,767)

    Long

    Store integer values in the range of (-

    2,147,483,468) - (+ 2,147,483,468)

    SingleStore floating point value in the range of

    (-3.4x10-38) - (+ 3.4x1038)

    DoubleStore large floating value which

    exceeding the single data type value

    Currencystore monetary values. It supports 4 digits

    to the right of decimal point and 15digits to the left

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    10/16

    String

    Use to store alphanumeric values. Avariable length string can store

    approximately 4 billion charactersEx. Dim MyString As String * 10

    MyString = "Chilkat" ' MyStringcontains "Chilkat " PrintRTrim$(MyString) ' prints "Chilkat"

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    11/16

    Date

    Use to store date and time values. Avariable declared as date type can storeboth date and time values and it can

    store date values 01/01/0100 up to12/31/9999

    Ex. Use the Date data type to contain

    date values, time values, or date andtime values.

    The default value ofDate is 0:00:00

    (midnight) on January 1, 0001.

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    12/16

    Boolean Boolean data types hold either a true or false value.

    These are not stored as numeric values and cannotbe used as such. Values are internally stored as -1(True) and 0 (False) and any non-zero value is

    considered as true. Dim runningVB As Boolean ' Check to see if program

    is running on Visual Basic engine. If scriptEngine ="VB" Then runningVB = True End If

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    13/16

    Variant

    Stores any type of data and isthe default Visual Basic data

    type. In Visual Basic if wedeclare a variable without anydata type by default the data

    type is assigned as default.Ex. Dim A Dim A as Variant

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    14/16

    Operators in Visual Basic

    Operators Description Example Result

    + Add 5+5 10

    - Substract 10-5 5

    / Divide 25/5 5

    \ Integer Division 20\3 6

    * Multiply 5*4 20

    ^Exponent (power

    of)3^3 27

    Mod

    Remainder of

    division 20 Mod 6 2

    &String

    concatenation"George"&"

    "&"Bush""George Bush"

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    15/16

    Relational Operators

    Operators Description Example Result

    > Greater than 10>8 True

    < Less than 10=Greater than or

    equal to20>=10 True

  • 7/30/2019 Visual Basic 6 (VB6) Data Types

    16/16

    Logical Operators

    OperatorsDescription

    OROperation will be true if either of the

    operands is true

    ANDOperation will be true only if both the

    operands are true