{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

HW 2 part 2 codes

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

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

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

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

View Full Document
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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online