CIS 451: ASP.NET Concepts - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

CIS 451: ASP.NET Concepts

Description:

VBScript. subset of VBA, for Internet applications. Previous VBScript ' ... VBScript Data Types. all VBScript data stored as variants. can't declare with types ... – PowerPoint PPT presentation

Number of Views:550
Avg rating:3.0/5.0
Slides: 31
Provided by: RalphWe2
Category:
Tags: asp | cis | net | concepts | vbscript

less

Transcript and Presenter's Notes

Title: CIS 451: ASP.NET Concepts


1
CIS 451 ASP.NET Concepts
  • Dr. Ralph D. Westfall
  • January, 2009

2
Former Visual Basic Family
  • Visual Basic
  • standalone development product
  • VB for Applications
  • subset of VB
  • works within Microsoft applications
  • VBScript
  • subset of VBA, for Internet applications

3
Previous VBScript
  • "chopped down" version of Visual Basic
  • many of same
  • data types
  • syntax
  • control structures
  • functions

4
ASP.NET Is Not Just VB
  • can also use C, C, C, J, JScript.NET, Perl,
    and other languages
  • just as CGI can work with different languages
  • ASP.NET supports more than 25 languages
  • additional languages expected to be adapted to
    work with .NET in the future

5
VBScript Data Types
  • all VBScript data stored as variants
  • can't declare with types as in VB
  • actual type based on data assigned to variable
  • can subsequently use a different type
  • Dim varLength
  • varLength 5
  • varLength "five"

6
ASP.NET Data Types
  • 11 primitive types built into .NET framework
  • 4 integer types Byte, Short, Integer, Long
  • 3 decimal types Single, Double, Decimal
  • Text String and Char (Char is really a )
  • Other Date and Boolean
  • objects are also a data type
  • but not a primitive type

7
Variable Naming Conventions
  • in some programming languages, people like to
    attach the data type to the front of the variable
    name
  • also known as "Hungarian notation"
  • popular at Microsoft
  • not popular with Java programmers
  • cultural issue between Microsoft and rest of
    world?
  • bottom line Prof. Westfall likes for objects

8
Object Naming Convention
  • btn Button
  • cbo Combobox
  • chk Checkbox
  • dg Data grid
  • frm Form
  • gpb Group box
  • img Image
  • lbl Label
  • lst Listbox
  • mnu Menu
  • opt Option button
  • (Radio button)
  • pic Picture
  • rpt Report control
  • txt Text Box

9
Object Naming Issues
  • advantages of a convention
  • makes code easier to debug and maintain
  • improves your grade on projects
  • disadvantages of a convention
  • 1-letter declarations dont always match
  • Dim sName as string
  • Dim fSmallDecimal as Single
  • extra work

10
Other Variable Naming Issues
  • all variable names must start with a letter
  • use letters and numbers
  • avoid other (special) characters (other than
    underscore _ )
  • capitalize initial letters of words after
    prefixes
  • datQuarterStarts
  • datQuarterEnds
  • use meaningful names of reasonable length

11
Other Data Types
  • object
  • can have multiple values of different types
  • empty memory location but no value
  • NULL no data at all
  • nothing (not even 0 or blank or "")
  • has no memory location
  • error

12
Declaring Variables
  • implicit (ASP.NET figures out type)
  • Dim strCustName "Lee" 'string
  • only works if StrictFalse (next slide)
  • explicit (better)
  • Dim strCustName as String
  • strCustName "Lee"
  • 'OR
  • Dim strCustName as String"Lee"

13
Setting Declaration Options
  • to force declaring all variables and to avoid
    type conversion errors
  • lt_at_ Page Language"VB" StrictTrue gt
  • put on very first line of file of ASP file
  • could use ExplicitTrue instead
  • allows implicit declarations e.g.,
  • Dim strCustName"Li" 'no as Type

14
Array Variables
  • Dim strUSAStates(49)
  • strUSAStates(0) "AL"
  • counts from 0 (same as in C, etc.)
  • Redim Preserve strUSAStates(50)
  • changes size without losing current data
  • Dim strTicTacToe(2,2)
  • for a 3 x 3 array

15
Constant
  • value can't change
  • naming convention is to capitalize all letters in
    name
  • makes code more understandable
  • Const TAX_RATE .28
  • UNDERSCORES_SEPARATE_WORDS
  • in contrast to "camel case" coding

16
Variable Scope
  • procedure level (local i.e., inside a Sub)
    variable values are NOT available elsewhere in
    ASP.NET code
  • other variables (global level, outside of any
    Subs) are accessible to all ASP.NET code in a
    page (all Subs, and in HTML)
  • 'see notes

17
Subprocedures
  • Sub ProcName(arg1 as Type, etc.)
  • 'lines of code, including arg1
  • ' other local/global variables
  • End Sub
  • Call ProcName(arg1, etc.)

18
Operators
  • assignment e.g., CustAge 22
  • , -, , / (arithmetic)
  • exponentiation e.g.,
  • RSquare Radius2
  • how does Java do exponentiation?

19
Operators - 2
  • \ operator for integer division (contra / )
  • 7 / 4 1.75
  • \ gives integer part 7 \ 4 1
  • decimals are rounded off before integer division
  • MOD gives remainder 7 MOD 4 3
  • "clock arithmetic"

20
Concatenation Operation
  • link together in series or chain (Webster)
  • concatenates items regardless of type
  • "Le " "Dinh" "Le Dinh"
  • 1 1 "11"
  • concatenates strings like does, but
  • 1 "1" 2 'except when StrictOn

21
Concatenation - 2
  • concatenation can construct ASP.NET code also
    (not just for calculations)
  • intIndex 2
  • Session("intProdQuantity" _ intIndex)
  • evaluates to
  • Session("intProdQuantity2")
  • buya.aspx

22
Comparison Operators
  • (equal how does Java do this?)
  • lt gt (not equal Java?)
  • lt (less than)
  • gt (greater than)
  • lt (less than or equal)
  • gt (greater than or equal)

23
Logical Operators
  • AND (Java?)
  • OR
  • NOT
  • If nAge gt 65 AND strLocal TRUE Then

24
String Handling Functions, Etc.
  • strText.ToLower(), "abc".ToUpper()
  • (converts to capitals or lower case)
  • Len(strText) (or strText.Length)
  • Left(strText, intN), Right(strTxt, intN)
  • (returns intN left or right characters)
  • Mid(strText, intWhere, intN)
  • (intN characters, starting at intWhere)
  • Excel demo

25
String Handling - 2
  • strText.IndexOf(StrFind, intStart)
  • strText.IndexOf("some text")
  • (finds location actual numeric position of
    StrFind variable or text within a String variable
    or literal starting at intStart)
  • example check e-mail address format
  • intLoc strText.IndexOf ("_at_", 2)
  • (if returns value lt1, string wasn't found)

26
String Handling - 3
  • strText " abc "
  • strText.TrimStart()
  • "abc ".TrimEnd()
  • remove spaces from left or right side
  • strText.Trim()
  • remove spaces from both sides

27
Converting Variable Types
  • strType TypeName(intWeight)
  • (returns data type)
  • intTons CInt(dblTons)
  • strPop CStr(lngPopulation)
  • (convert variables to Integer, String, etc.)

28
Checking Types, Etc.
  • IsNumeric(Request.QueryString("Zip"))
  • checks to see if data is numeric
  • IsDate(Request.QueryString("DoB"))
  • checks to see if data is in a date format
  • If Request.QueryString("CustName") "" Then
  • If Request.QueryString("Zip") Is Nothing Then
  • checks for missing data

29
Line Continuations
  • problem many VB.NET functions won't work if
    split onto more than 1 line
  • solution use _ (space underscore) just before
    line break
  • If Request.Form("CustEMail").IndexOf("_at_") _ gt 2
    AND _
  • Request.Form("CustEMail").IndexOf(".") _
  • gt 4 Then

30
web.config Shows Code Errors
  • Visual Studio.NET creates with project
  • lt!-- Web.Config Configuration File --gt
  • ltconfigurationgt
  • ltsystem.webgt
  • ltcustomErrors mode"Off"/gt
  • lt/system.webgt
  • lt/configurationgt
Write a Comment
User Comments (0)
About PowerShow.com