Tutorial 8
4 pages
Latin
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
4 pages
Latin
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

Tutorial 8:  Example Use of a two­dimensional Array (taken fromProgramming in Visual Basic .NET, by Bradley and Millspaugh) 1) You are going to create a project that looks up the driving distance between two cities. Use two drop­down lists that contain the names of the cities as indicated in the table below.  Label one list “Departure” and the other “Destination.  Use a button click event to calculate the distance.  Use a two dimensional array to store the distances. 2) Your GUI will look as follows: 3) Table of driving distances follows: Boston  Chicago  Dallas  Las  Los  Miami  New  Tor­  Van­  D.C Vegas  Angeles  Orleans  onto  cover Boston  0  1004  1753  2752  3017  1520  1507  609  3155  448 Chicago  1004  0  921  1780  2048  1397  919  515  2176  709 Dallas  1753  921  0  1230  1399  1343  517  1435  2234  1307 Las  2752  1780  1230  0  272  2570  1732  2251  1322  2420 Vegas Los  3017  2048  1399  272  0  2716  1858  2523  1278  2646 Angeles Miami  1520  1397  1343  2570  2716  0  860  1494  3447  1057 New  1507  919  517  1732  1858  860  0  1307  2734  1099Orleans Tor­  609  515  1435  2251  2523  1494  1307  0  2820  571 onto Van­  3155  2176  2234  1322  1278  3447  2734  2820  0  2887 cover D.C.  448  709  1307  2420  2646  1057  1099  571  2887  0 4) Properties Plan: Properties Plan for Tutorial 8 Object  Property  Setting Form1  Name  Form1 Text  Driving Distance AcceptButton  btnLookUp Label1  Text  Departure: Label2  Text  ...

Informations

Publié par
Nombre de lectures 80
Langue Latin

Extrait

Tutorial 8:Example Use of a twodimensional Array (taken fromProgramming in Visual Basic .NET, by Bradley and Millspaugh)
1) You are going to create a project that looks up the driving distance between two cities. Use two dropdown lists that contain the names of the cities as indicated in the table below. Labelone list “Departure” and the other “Destination.Use a button click event to calculate the distance.Use a two dimensional array to store the distances.
2) Your GUI will look as follows:
3) Table of driving distances follows: Boston Chicago Dallas LasLos MiamiNew TorVan D.C Vegas AngelesOrleans ontocover Boston 01004 17532752 30171520 1507609 3155448 Chicago 10040 9211780 20481397 919515 2176709 Dallas 1753 9210 12301399 1343517 14352234 1307 Las 27521780 12300 2722570 17322251 13222420 Vegas Los 30172048 1399272 02716 18582523 12782646 Angeles Miami 15201397 13432570 27160 8601494 34471057 New 1507919 5171732 1858860 01307 27341099
1307 2420 2646
1435 2251 25231494 13070 2820571
Label1 Label2 cboRow
2234 1322 1278
btnLookUp
Label3 lblDistance
btnClear
btnExit
1057 1099571 28870
Orleans Tor 609515 onto Van 31552176 cover D.C. 448709
Setting Form1 Driving Distance btnLookUp Departure: Destination: cboRow Boston Chicago Dallas Las Vegas Los Angeles Miami New Orleans Toronto Vancover Washington, DC DropDownList cboCol Boston Chicago Dallas Las Vegas Los Angeles Miami New Orleans Toronto Vancover Washington, DC DropDownList Distance in Miles: lblDistance
Property Name Text AcceptButton Text Text Name Items
3447 27342820 0
cboCol
4) Properties Plan: Properties Plan for Tutorial 8
btnLookUp &Distance btnClear C&lear btnExit E&xit
DropDownStyle Text Name Text Name Text Name Text Name Text
2887
DropDownStyle Name Items
Object Form1
5) Code ' Description: Look up the driving distance in miles between ' adeparture city and a destination city.Make use of ' twodimensional array that acts as a lookup table. ' Public ClassForm1 InheritsSystem.Windows.Forms.Form
' Declare modulelevel variable ' Declare the 2Dimensional array that will hold the distances ' betweencities DimdistanceInteger(,)As Integer= { _ {0I, 1004I, 1753I, 2752I, 3017I, 1520I, 1507I, 609I, 3155I, 488I}, _ {1004I, 0I, 921I, 1780I, 2048I, 1397I, 919I, 515I, 2176I, 709I}, _ {1753I, 921I, 0I, 1230I, 1399I, 1343I, 517I, 1435I, 2234I,1307I}, _ {2752I, 1780I, 1230I, 0I, 272I, 2570I, 1732I, 2251I, 1322I, 2420I}, _ {3017I, 2048I, 1399I, 272I, 0I, 2716I, 1858I, 2523I, 1278I, 2646I}, _ {1520I, 1397I, 1343I, 2570I, 2716I, 0I, 860I, 1494I, 3447I, 1057I}, _ {1507I, 919I, 517I, 1732I, 1858I, 860I, 0I, 1307I, 2734I, 1099I}, _ {609I, 515I, 1435I, 2251I, 2523I, 1494I, 1307I, 0I, 2820I, 571I}, _ {3155I, 2176I, 2234I, 1322I, 1278I, 3447I, 2734I, 2820I, 0I, 2887I}, _ {448I, 709I, 1307I, 2420I, 2646I, 1057I, 1099I, 571I, 2887I, 0I}}
Private SubbtnLookUp_Click(ByValsenderAsSystem.Object,ByVale AsSystem.EventArgs)HandlesbtnLookUp.Click ' Look up driving distances between two selected cities ' Departure city selected from the departure combo box ' determines the row index into the distanceInteger array ' declared as a modulelevel variable.The destination ' city selected from the destination combo box determines ' the column index into the distanceInteger array.Both ' are used as indexes to determine the correct look up ' value.
DimdepartureIndexIntegerAs Integer DimdestinationIndexIntegerAs Integer
departureIndexInteger = cboRow.SelectedIndex destinationIndexInteger = cboCol.SelectedIndex
IfdepartureIndexInteger <> 1AnddestinationIndexInteger <>  1Then lblDistance.Text = distanceInteger(departureIndexInteger, destinationIndexInteger).ToString("N") Else MessageBox.Show("Select the destination and departure city.","Information Missing", _ MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End Sub
Private SubbtnClear_Click(ByValsenderAsSystem.Object,ByVale AsSystem.EventArgs)HandlesbtnClear.Click
' Remove the selection from the departure and destination ' comboboxes and clear the driving distance cboRow.SelectedIndex = 1 cboColumn.SelectedIndex = 1 lblDistance.Text ="" End Sub Private SubbtnExit_Click(ByValsenderAsSystem.Object,ByValeAs System.EventArgs)HandlesbtnExit.Click ' Terminate the program Me.Close() End Sub End Class
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents