Working With Variables

Home  »  ASP  »  Working With Variables


     Variable is used for storing a value and There are many different data types o those are used for specifying the type of data which a variable will hold The various type of data types.

Contents

  • What Is a Variable?
  • Data Types
  • VB Script Operators
  • What Is a Variable?

    A variable is used for storing a value either a number or a character and a variable also vary its value means it may change his value Variables are used for given names to locations in the Memory of Computer where the different constants are stored.

    Declaration of Variable
    We know that in other Programming Languages it is must to first declare a variable and then use that variable if you doesn't declare a variable before using Compiler will gives you an error But Vbscript is Derived from Visual basic So that is provides us the faculty like Vb it Provides Implicit Declaration Means there is no need to declare a variable before using it In This There is no necessary to declare a variable Compiler will understand itself and the default data type will be variant but when you puts the data into variable then it will understand the date type of variable when you assign some date into the Variable.

    If you wants to first Declare a variable before using or if you wants to Restrict a user to first declare a variable then use that Then you must have to use option Explicit in top of your coding after Directive Line.

    <% Option Explicit %>

    In Vbscript a Variable is declared by using dim Keyword which stands for Dimension or declare with no data type because type of data of a variable is judged when we actually specifying the data into the variable.

    <%
        Option Explicit
        Dim myVar
    %>





    Data Types

    There are many different data types o those are used for specifying the type of data which a variable will hold The various type of data types are as follows:

    Integer
    An integer is a whole number that is number with no decimal portion

    Floating data type
    Floating Data type numbers have a decimal values But the difference b/w integer and float is precisions or decimal those are supported by float but not by integer

    String
    String which is also called as collection of characters ,numbers, symbols and A String is always Puts into the double quotes like "Hello how are you " etc

    Date
    A date variable is used for storing a date value which is date and time in nature and we can operate various types of date and time functions on date data.

    Boolean
    Special Data type which contains only two values like true or either false These are used when we wants to make a decision Then Action of Condition is depended on result which is to be given in either true or false

    Currency
    Currency data type is used for string money values this is special data type which is special data type which is specially designed for Money values

    Object
    The object data type is used when we wants to referencing a variable to another Asp Objects

    Variant
    This is the default data type that is used for storing any data into the variable a number, string or etc. In Vbscript variables only hold variant data type which is also called as object type The actual data type is identified when we specify the data into the variable





    VB Script Operators

    VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation operators, and logical operators.

    Assignment Operator (=)(VBScript)
    Assigns a value to a variable or property

    Variable name=value
    Arguments

    Variable
    Any variable or any writable property.

    Value
    Any numeric or string literal,constant, or expression.

    Arithmetic Operators
    They are
    ^ Operator
    * Operator
    / Operator
    \ Operator
    Mod Operator
    + Operator
    - Operator
    Concatenation Operators

    Comparison Operators
    As the name implies, the comparison operators are used to compare one or more variables, numbers, and constants and their combination. These operators are used in statment which compares two different numberic expressions and returns a Boolean value of TRUE if the statement is true. If not, the statement returns FALSE. The typical usage is as follows:

    _expression1 Operator _expression2

    where _expression1 and _expression2 are any numeric _expression. A description of operators are found in the table below:

    OperatorTo Determine if..
    < One_expression is less than another _expression.
    > One_expression is greater than another _expression.
    <= One_expression is less than or equal to another _expression.
    >= One_expression is greater than or equal to another _expression.
    = Two expressions are equal.
    <> Two expressions are not equal.


    Conjunction And Operator
    The conjuction operator compares two or more variables in some type of test. The syntax for the conjuction operator is

    result = _expression1 And _expression2

    The below table displays the result variable in relation to _expression1 and _expression2. In order to obtain True in the result variable, both _expression1 and _expression2 must be true.
    if _expression1and _expression2then result
    True True True
    False True False
    True False False
    False False False


    Disjunction Or Operator
    The syntax and usage of Or operator is similar to And operator

    result = _expression1 or _expression2

    The result variable in relation to _expression and _expression2 is summarized in below table. In order to obtain True in result variable, at least one of _expression1 or _expression2 must be true.
    if _expression1and _expression2then result
    True True True
    False True True
    True False True
    False False False


    Exclusion XOR Operator
    The exclusion operator is another in the family of logical operators that you can use to make decisions based on the contents of one or more expressions. It checks whether one and only one condition is exclusively true. The syntax of the exclusion operator is:

    result = _expression1 And _expression2

    if _expression1and _expression2then result
    True True False
    False True True
    True False True
    False False False


    Logical Equivalence Eqv and Implication Imp Operator

    The remaining two logical operators Eqv and Imp are rarely used in _VBScript. They are inherited from Visual Basic, and there are used for bitwise operation. In _VBScript they might be used in some sophisticated logical construction, however, I can not even give you an example which will be intuitively obvious. If you still want to get to know about them, please, refer to _VBScript links.






    Share on Google Plus
      Blogger Comment
      Facebook Comment