Top Banner
CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009
30

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

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

CIS 451: ASP.NET Concepts

Dr. Ralph D. WestfallJanuary, 2009

Page 2: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 3: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Previous VBScript "chopped down" version of Visual

Basic many of same

data types syntax control structures functions

Page 4: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 5: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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"

Page 6: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 7: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 8: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Object Naming Conventionbtn Button

cbo Comboboxchk Checkboxdg Data grid frm Formgpb Group boximg Imagelbl Label

lst Listboxmnu Menuopt Option button (Radio button) pic Picturerpt Report control txt Text Box

Page 9: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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 don’t always match

Dim sName as stringDim fSmallDecimal as Single

extra work

Page 10: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 11: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 12: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Declaring Variables implicit (ASP.NET figures out type)

Dim strCustName = "Lee" 'string only works if Strict=False (next

slide) explicit (better)

Dim strCustName as String strCustName = "Lee" 'OR Dim strCustName as String="Lee"

Page 13: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Setting Declaration Options to force declaring all variables and

to avoid type conversion errors <%@ Page Language="VB" Strict=True %>

put on very first line of file of ASP file could use Explicit=True instead

allows implicit declarations e.g., Dim strCustName="Li" 'no as Type

Page 14: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 15: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 16: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 17: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Subprocedures Sub ProcName([arg1 as Type, etc.])

'lines of code, including arg1 '& other local/global variables End Sub

Call ProcName([arg1, etc.])

Page 18: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Operators = assignment e.g., CustAge = 22 +, -, *, / (arithmetic) ^ exponentiation e.g., RSquare = Radius^2 how does Java do exponentiation?

Page 19: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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"

Page 20: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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 Strict=On

Page 21: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Concatenation - 2 concatenation can construct

ASP.NET code also (not just for calculations) intIndex = 2 Session("intProdQuantity" & _ intIndex)

evaluates to Session("intProdQuantity2") buya.aspx

Page 22: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Comparison Operators = (equal [how does Java do

this?]) < > (not equal [Java?]) < (less than) > (greater than) <= (less than or equal) >= (greater than or equal)

Page 23: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Logical Operators AND ([Java?]) OR NOT

If nAge > 65 AND strLocal = TRUE Then

Page 24: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 25: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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 ("@", 2) (if returns value <1, string wasn't found)

Page 26: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

String Handling - 3 strText = " abc " strText.TrimStart() "abc ".TrimEnd() remove spaces from left or right

side

strText.Trim() remove spaces from both sides

Page 27: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

Converting Variable Types strType = TypeName(intWeight) (returns data type)

intTons = CInt(dblTons) strPop = CStr(lngPopulation) (convert variables to Integer,

String, etc.)

Page 28: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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

Page 29: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

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("@") _ >= 2 AND _

Request.Form("CustEMail").IndexOf(".") _ >= 4 Then

Page 30: CIS 451: ASP.NET Concepts Dr. Ralph D. Westfall January, 2009.

web.config Shows Code Errors Visual Studio.NET creates with project<!-- Web.Config Configuration File --><configuration> <system.web> <customErrors mode="Off"/> </system.web></configuration>