HW 2 part 2 codes

HW 2 part 2 codes - For yloc = 1 To 9 ztest = getz(xloc,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Option Explicit Dim x(15) As Integer, y(15) As Integer Dim pop(15) As Integer Private Sub CommandButton1_Click() Call Main End Sub Sub Main() Dim i As Integer, j As Integer Dim d As Single, z As Single, ztest As Single Dim xloc As Integer, yloc As Integer Dim xbest As Integer, ybest As Integer Clear the previous result Worksheets("Firehouse").Select Range("b21. .d21").Select Selection.ClearContents pop(0) = 0 For i = 1 To 15 x(i) = Worksheets("Firehouse").Cells(3 + i, 2).Value y(i) = Worksheets("Firehouse").Cells(3 + i, 3).Value pop(i) = Worksheets("Firehouse").Cells(3 + i, 4).Value pop(0) = pop(0) + pop(i) Next i z = 1E+20 xbest = -1 ybest = -1 For xloc = 1 To 9
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: For yloc = 1 To 9 ztest = getz(xloc, yloc) If (ztest < z) Then xbest = xloc ybest = yloc z = ztest End If Next yloc Next xloc Worksheets("Firehouse").Range("b21").Value = xbest Worksheets("Firehouse").Range("c21").Value = ybest Worksheets("Firehouse").Range("d21").Value = z End Sub Sheet1 Page 2 Function getz(r As Integer, s As Integer) As Single Dim i As Integer, davg As Single, poptotal As Single davg = 0 For i = 1 To 15 'straight line davg = davg + pop(i) * Sqr(((x(i) - r) ^ 2) + ((y(i) - s) ^ 2)) 'over the road davg = davg + pop(i) + Abs(x(i) - r) + Abs(y(i) - s) Next i davg = davg / pop(0) getz = davg End Function...
View Full Document

This note was uploaded on 03/30/2008 for the course CE 297A taught by Professor List during the Spring '08 term at N.C. State.

Page1 / 2

HW 2 part 2 codes - For yloc = 1 To 9 ztest = getz(xloc,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online