Escolar Documentos
Profissional Documentos
Cultura Documentos
F5227VISUALBASIC.NET PROGRAMMING
CourseLearningOutcome(CLO)
Upon completion of this course, students should be able to : 1. Create a simpe VB.NET based application based on the Windows Application template. 2. Describe on essential terminology including memory, data types and graphical user interface interface. 3. Apply object oriented programming techniques to create classes, add methods and add properties. 4. create a simple VB.NET based Web forms application that uses an XML Web Service and manipulate data in database by using Microsoft ADO.NET.
Introduction
Computerprogramsareprocessorsofdata andtherefore,theyneedofwayof representingvarioustypesofdata numbers, alphabeticcharacters,specialcharacters,and alphabetic characters special characters and thelike insidethecomputer. Duringprocessingprogramsneedawayto holdonto tostore thesedatainside computermemory.
DataTypes
Incomputerprocessing,thefollowingare commonfordeclaringtheusualtypesofdata involved:
Short A non decimal (whole) number with a value Short.Anondecimal(whole)numberwithavalue intherangeofthe32,768to+32,767. Integer.Anondecimal(whole)numberwitha valueintherangeofthe2,147,483,648to +2,147,483,647.
DataTypes
Long.Anondecimal(whole)numberwithavalue intherangeofthe9,223,372,036,854,775,808to +9,223,372,036,854,775,807. Single.Afloatingpoint(decimal)positiveor negativenumberwithavalueintherangeofupto the3.402823E38(scientificnotation). Double Afloatingpoint(decimal)positiveor negativenumberwithavalueintherangeofupto the1.79769313486232E308.
DataTypes
Decimal.Adecimalnumberwithavalueinthe rangeofupto +79,228,162,514,264,337,593,950,335.without decimalprecisionanduptothe +7.9228162514264337593543950335with28 placesofdecimalprecision. String.Anynumberofspecial, numerical,alphabeticandspecialcharacters.
3/14/2012
DataTypes
Date DatesintherangebetweenJanuary1,0001 toDecember31,9999andtimesintherange between0:00:00tothe23:59:59. Boolean.ThevalueofTrueorFalse.
Variables
Variablesarenamedstorageareasinside computermemorywhereaprogramplaces dataduringprocessing. A program sets aside these storage areas by Aprogramsetsasidethesestorageareasby declaringvariables,thatis,byassigningthem anameandindicatingwhattypesofdatawill occupytheseareasduringprocessing.
DeclaringVariables
Twoprinciplewaystoaddvariablestoyour applications. Thefirstmethod calledimplicitdeclaration istoletVisualBasicautomaticallycreatethe is to let Visual Basic automatically create the variableforyou. ImplicitdeclarationmeansthatVisualBasic automaticallycreatesavariantforeach identifieritrecognizesasavariableinan application. Thesecondapproachtodeclaringvariableis toexplicitlydeclarethemwithoneofthe followingkeywords:Dim,Static,Private,and Public. Public
DeclaringVariables
Variablesareusedtostoredata. VariablesaredeclaredwiththeDim keyword. Dim standsforDimension. VariablesaredeclaredusingtheDim statementwhosegeneralformatisshown below: Dim variable As type wheretypeisoneofthedatatypes permissibleinVisualBasicandvariableisa programmersuppliednameforthestorage area.
3/14/2012
Example
DimVariableNameAsDataType StaticVariableNameAsDataType PrivateVariableNameAsDataType PublicVariableNameAsDataTyp Public VariableName As DataTyp
NamingVariables
VBnamingconventionsandavariablename must:
Becomposedonlyofalphabetic,underscore,and numericcharacters. numeric characters Beginwithanalphabeticcharacter,orthe underscore(_)character. Notcontainanyembeddedblankspaces. NotbethesameasaVisualBasickeyword,words thecompriseoftheVisualBasiclanguageitself.
NamingVariables
Nopunctuationmarksareallowed. Thenamecanbeaslongas255characters Variablenamescantbeduplicatedwiththe samescope.
Thismeans,forexample,thatyoucanthavetwo variablesofthesamenamewithinaprocedure. Youcan,however,havetwovariableswiththe samenameintwodifferentprocedures.
Remember
Variablenamesarenotcasesensitive,sothe nameexpressedinuppercasecharacters referstothesamestorageareaasaname expressedinlower casecharactersand expressed in lowercase characters and however,forprogrammingconsistency,andto avoidunnecessaryerrors,itisbesttoexpress avariableasitisoriginallydeclared.
DataTypes
Whendeclaringavariableanindicationcanbe givenaboutwhattypeofdatawillbestored andtherearemanydatatypespermissible underVisualBasic. under Visual Basic
Example
DimMy_CounterAsInteger DimMy_SalaryAsDecimal DimMy_GreatBigNumberAsDouble DimMy_NameAsString Dim My Name As String DimMy_BirthdayAsDate DimMy_Current_TimeAsDate DimMy_DecisionAsBoolean
3/14/2012
AssigningValuestoVariables
AssigningExpressionstoVariables
DimThe_AnswerAsDecimal DimVar_AAsDecimal=2.5 DimVar_BAsDecimal=3.5 The_Answer=5 (Var A + Var B) The Answer = 5 *(Var_A+Var_B)
variable=value
AccessSpecifiers
Accessspecifierslet'susspecifyhowa variable,methodoraclasscanbeused. Themostcommonlyusedone's:
P bli Gi Public:Givesvariablepublicaccesswhichmeans i bl bli hi h thatthereisnorestrictionontheiraccessibility Private:Givesvariableprivateaccesswhichmeans thattheyareaccessibleonlywithintheir declarationcontent
AccessSpecifiers
Protected:Protectedaccessgivesavariable accessibilitywithintheirownclassoraclass derivedfromthatclass Friend:Givesvariablefriendaccesswhichmeans thattheyareaccessiblewithintheprogramthat containstheirdeclaration ProtectedFriend:Givesavariablebothprotected andfriendaccess
AccessSpecifiers
Static:Makesavariablestaticwhichmeansthat thevariablewillholdthevalueeventhe procedureinwhichtheyaredeclaredends Shared:Declaresavariablethatcanbeshared acrossmanyinstancesandwhichisnotassociated withaspecificinstanceofaclassorstructure ReadOnly:Makesavariableonlytobereadand cannotbewritten
Example
Imports System.Console Module Module1 Sub Main() Dim a,b,c as Integer g yp g 'declaring three variables of type integer a=10 b=20 c=a+b Write("Sum of a and b is" & c) End Sub End Module