Vous êtes sur la page 1sur 3

3/14/2012

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.

Topic3.0 CommonProgrammingTechniques 3.2 ControlStructures

Introduction
AnArrayisamemorylocationthatisusedto storemultiplevalues. Allthevaluesinanarrayareofthesametype, suchasint orstring andarereferencedby such as int or string and are referenced by theirindex orsubscriptnumber,whichisthe orderinwhichthesevaluesarestoredinthe array.Thesevaluesarecalledtheelements of thearray. Thenumberofelementsthatanarray containsiscalledthelengthofthearray.

TypesofArray
Arrayscanbesingleormultidimensional. Youcandeterminethedimensionsofanarray bythenumberofsubscriptsthatareusedto identifythepositionofanyarrayelement. id if h ii f l Asingledimensionalarrayisidentifiedby onlyasinglesubscriptandanelementina twodimensional arrayisidentifiedbytwo subscripts.

ArrayDeclaration
Thearraydeclarationcomprisesthenameof thearrayandthenumberofelementsthe arraycancontain. The Syntax of single dimension array is as TheSyntaxofsingledimensionarrayisas follows.
Datatype[]ArrayName=newDataType[numberof elements]; e.g. string[]studentname=newstring[5];

3/14/2012

Youcanassignthevaluesatruntimeoreven atthedesigntime.
Designtimedeclaration:
Studentname [0]=Rohan [0]= Rohan Studentname [1]=Mohan .. Studentname[10]=Nitin

Allarraysstartswiththeindexof0i.e. AllarraysareZeroBased.Thisimpliesthat abovearraycanstore10elements.Here0,is thestartingindexorthelowerboundofthe the starting index or the lower bound of the arrayand9istheupperboundwhilethe lengthofthearrayis10.

Example
TheSyntaxformultidimensionarrays:
Dim ArrayName (number of 1st element, number of 2nd element,.) as element data type.
Dim ArrayName( number of rows, number of columns) as element data type of two dimension. Dimstudentdetails(10,2)asstring Indexpositionsofarrayelements. 0,00,1 1,01,1 2,02,1 3,03,1 3031 10,010,1 studentdetails(0,0)=Manoj studentdetails(0,1)=Malik TodisplayMalikweneedtousetheindexpositionofthearrayandsay, Studentdetails(0,1).

DynamicArrays.
Manytimeswefeelthatthesizeofarrayin notenoughortoomuchthenrequired. Asweknowthatarraywillallocatememory locationwhenitsdeclared,sotoreleaseor location when its declared so to release or addmoreweneedtochangethedimension ofthearraywhichhasbeenpredeclared.

DynamicArrays.
Wecancreateadynamicarraybynot specifyingthesizeofthearrayatthetimeof arraydeclaration. Syntax: Dimstudent_names()asstring
Intheabovesyntaxyouwillseethatnumberofelementsare notmentioned.Nowtoredeclaretheelementswemakeuse ofReDimforanarraytochangeitsdimension.

3/14/2012

ReDim
e.g. Dimstudent_names()asstring ReDimstudent_names(10)
ReDimcanalsochangethesizeofmulti dimensionalarrays. Youcanchangethenumberofdimensionsinan array,butyoucannotmakeamultidimensionalarray toasingledimensionorlesserthantheoriginal dimension.

e.g.
'Declaringthearray Dimstudent_details(10,15)asstring Resizingthearray 'Resizing the array ReDimstudent_details(10,25)
Thisstatementdoesnotchangethedatatypeofthearrayelementor initializethenewvaluesforthearrayelements. Thisstatementcanbeusedattheprocedurelevelonlynotattheclass levelormodulelevel.