I would see it used like this:
Option Explicit
Option Base 0
Private Type POINT
x As Double
y As Double
End Type
Sub Main()
Dim XP, YP, XP1, YP1
Dim poly() As POINT
Dim b As Boolean
Dim x As Double, y As Double
Dim i As Long, j As Long
ReDim poly(0 To 19)
' Polygon
XP = Array(0#, 1#, 1#, 0#, 0#, 1#, _
-0.5, -1#, -1#, -2#, -2.5, _
-2#, -1.5, -0.5, 1#, 1#, 0#, _
-0.5, -1#, -0.5)
YP = Array(0#, 0#, 1#, 1#, 2#, 3#, 2#, _
3#, 0#, -0.5, -1#, -1.5, -2#, _
-2#, -1.5, -1#, -0.5, -1#, _
-1#, -0.5)
' Test Points
XP1 = Array(0.5, 0.5, -0.5, 0.75, 0, _
-0.5, -1, -1.5, -2.25, 0.5, 0.5, -0.5)
YP1 = Array(0.5, 1.5, 1.5, 2.25, 2.01, _
2.5, -0.5, 0.5, -1, -0.25, -1.25, -2.5)
' writing to the worksheet is not required
' but supports graphing the data to verify
Cells(2,1) = "XP" : Cells(3, 1) = "YP"
Cells(4,1) = "XP1" : Cells(5,1) = "YP1"
Cells(2, 2).Resize(1, 20) = XP
Cells(3, 2).Resize(1, 20) = YP
Cells(4, 2).Resize(1, 12) = XP1
Cells(5, 2).Resize(1, 12) = YP1
j = 0
For i = LBound(XP) To UBound(XP)
poly(j).x = XP(i)
poly(j).y = YP(i)
j = j + 1
Next
j = 1
For i = LBound(XP1) To UBound(XP1)
x = XP1(i): y = YP1(i)
b = pnpoly(20, poly, x, y)
Cells(6, j).Offset(0, 1) = b
j = j + 1
Next
End Sub
Function pnpoly(npol As Integer, poly() As POINT, _
x As Double, y As Double) As Boolean
Dim inpoly As Boolean
Dim i As Integer, j As Integer
i = 0
j = npol - 1
inpoly = False
While (i < npol)
If ((poly(i).y <= y) And (y < poly(j).y)) Or _
((poly(j).y <= y) And (y < poly(i).y)) Then
If x < (poly(j).x - poly(i).x) * (y - poly(i).y) / _
(poly(j).y - poly(i).y) + poly(i).x Then
inpoly = Not (inpoly)
End If
End If
j = i
i = i + 1
Wend
pnpoly = inpoly
End Function
Note that I have changed the function a little to support the data used.
(integer=>double)
See description at:
http://tinyurl.com/y93rhr
or "spelled out"
http://209.85.165.104/search?q=cach...ps+"function+pnpoly"&hl=en&gl=us&ct=clnk&cd=5