Presentation is loading. Please wait.

Presentation is loading. Please wait.

INT213 Week 1.  A Named storage area (in RAM) that can hold a value (like a mailbox holding a letter)  Contents of a variable can be assigned, changed.

Similar presentations


Presentation on theme: "INT213 Week 1.  A Named storage area (in RAM) that can hold a value (like a mailbox holding a letter)  Contents of a variable can be assigned, changed."— Presentation transcript:

1 INT213 Week 1

2  A Named storage area (in RAM) that can hold a value (like a mailbox holding a letter)  Contents of a variable can be assigned, changed and viewed within a script  Values can consist of several Data Types ex: Numbers or strings (text).

3  Structure counter = 10 Data is placed into variables by assigning values. Whatever is on the right side of the equal sign is stored in a variable. Myname = “Fred Flinstone” Variable Name Assignment Operator Value String Value

4 Variables must begin with a letter, not an underscore or a number They cannot have more than 255 characters They cannot contain a period (full stop), a space or a dash You can use an underscore, but not as the first character  Variables are not case sensitive  Cannot be a reserved word (word used by VBScript) The names you use for variables is important. i. Describes what the variable holds and is used for ii. Makes scripts easier to read

5 <% ‘add apples to oranges Apples = 27 Oranges = 3 TotalFruit = apples + Oranges ‘output the result Response.Write “The are “ & TotalFruit & “ Pieces of fruit” %> Opening Script Tag tells server to process what follows as script Assign Vales to Variables Add Values in Variables together and assign to new Variable Output the total Closing script tag tells the sever the script is complete

6  Variables can contain a variety of data types but can only hold one value at a time. <% myValue = 10 myValue = “Hello There” myValue = 100.45 Response.write myValue %> As each variable is assigned a value, the previous value is replaced. Output value will be 100.45

7 Something as simple as spelling a variable name incorrectly could lead to serious problems <% Wages = 100.00 Raise =.25 NewWage = Wages * Rise Response.write “Your salary increase is “ & NewWage %> OutPut: Your salary increase is 0 This is called a LOGIC error. The script would execute properly, but the result would be incorrect

8  Option Explicit and DIM <% Option Explicit Dim Wages, Raise, NewWage Wages = 100.00 Raise =.25 NewWage = Wages * Raise Response.write “Your salary increase is “ & NewWage %> If any variable after the DIM line is spelled incorrectly, IIS would generate an error. The script would work until the error is corrected. Forces server to test that each variable used is spelled correctly. This command should be on the first line of the script List all variables used in script

9  The Scope of a Variable basically determines what it effects and how long it lives. There are three levels of Variables. 1. Page level 2. Session level 3. Application (global) level

10  At this level, Variables are available to the web page in which they were created.  Moving to another web page erases the values in these variables.  Simple Variables are considered Page Level Name = “Fred” Age = 45 See PageVar_page1.asp for a demo This file is located in the Blackboard week 1folder

11  Session Variables live within a browser session. Moving from page to page or web site to web site does not erase their values.  Session variables are stored on the server as long as browser is open or until session is timed out  Each time a new browser access the server, a session is created  Can be accessed from any page related to a web site Session(“myage”) = 45 Session Variables cannot be declared The variables will be demonstrated in class See SessionVar_page1.asp for a demo This file is located in the Blackboard week 1folder

12  These Variables can be accessed by any browser accessing a web site.  Multiple browser session (users) can access and alter these variables  Ex: Sites that tracks and displays number of users currently on-line are using Application Variables Application(“No_of_Users”) = 10 All users entering a web site would see the current value of this variable. See ApplicationVar_page1.asp for a demo This file is located in the Blackboard week 1folder


Download ppt "INT213 Week 1.  A Named storage area (in RAM) that can hold a value (like a mailbox holding a letter)  Contents of a variable can be assigned, changed."

Similar presentations


Ads by Google