View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
T_o_n_y T_o_n_y is offline
external usenet poster
 
Posts: 43
Default mismatch error and Variants

I added an argument to a subroutine and then started getting the By Ref
argument type mismatch error--even though it appears my arguments were of the
right type. I eventually "fixed it" by changing one of the arguments to
Variant rather than Integer. My question is, what's going on here? Why am I
getting a type mismatch when I'm correctly dimensioning my variables?

Here's the call to the sub
GetP WRow, AnIBlk
in which WRow is Dim as Integer, and AnIBlk is Dim as Boolean.

And the Sub itself follows (It's presented in its entirety, although the
subs it calls aren't included). As I said, WRow is declared "As Variant"
because that's the only way I could avoid the mismatch error...when I had it
"As Integer" I got the error every time. The other way I found I could avoid
the error was to declare WRow As Integer globally (that is, at the top of the
module).

I'd appreciate any insights!

Sub GetP(WRow As Variant, AnIBlk As Boolean)

Dim IncAgl() As Double
Dim msg As String
Dim i, j, k, l As Integer
Dim coord As Variant
Dim Pp() As Double

ReDim Preserve Cx(Ncnr + 2) As Double
ReDim Preserve Cy(Ncnr + 2) As Double
ReDim Preserve r(Ncnr) As Double
ReDim IncAgl(Ncnr) As Double

ReDim Pp(2 * Ncnr + 3) As Double
For i = 0 To Ncnr + 1
Pp(2 * i) = Cx(i): Pp(2 * i + 1) = Cy(i)
Next i

For i = 0 To 2 * Ncnr + 3
Cells(WRow + 8, 3 + i) = Pp(i)
Next i

If Not AnIBlk Then

Dim pc(0 To 2) As Double
Dim tc(0 To 2) As Double
Dim nc(0 To 2) As Double
Dim pt As Variant
Dim pla, nlaAs Double
Dim d, ang As Double
Dim bAAs Double
Dim bx() As Double
Dim by() As Double
Dim B() As Double
ReDim bx(2 * Ncnr + 1) As Double
ReDim by(2 * Ncnr + 1) As Double
ReDim B(2 * Ncnr - 1) As Double

For k = 1 To Ncnr
pc(0) = Cx(k - 1): pc(1) = Cy(k - 1): pc(2) = 0
tc(0) = Cx(k + 0): tc(1) = Cy(k + 0): tc(2) = 0
nc(0) = Cx(k + 1): nc(1) = Cy(k + 1): nc(2) = 0

pla = AglX(tc, pc)
nla= AglX(tc, nc)
IncAgl(k) = pla - nagl
If IncAgl(k) < 0 Then IncAgl(k) = 2 * pi + IncAgl(k)

d = Abs(r(k) / Tan(IncAgl(k) / 2))
ang = pla

bx(2 * k - 1) = Ppx(tc, ang, d)
by(2 * k - 1) = Ppy(tc, ang, d)
d = Abs(r(k) / Tan(IncAgl(k) / 2)) 'see figure
ang = nagl

bx(2 * k) = Ppx(tc, ang, d)
by(2 * k) = Ppy(tc, ang, d)
'Set lineObj = ThisDwg.ModelSpace.AddLine(tc, pt)
Next k

bx(0) = Cx(0): by(0) = Cy(0)
bx(2 * Ncnr + 1) = Cx(Ncnr + 1): by(2 * Ncnr + 1) = Cy(Ncnr + 1)

ReDim Pp(4 * Ncnr + 3) As Double

For i = 0 To 2 * Ncnr + 1
Pp(2 * i) = bx(i): Pp(2 * i + 1) = by(i)
Next i

For i = 1 To 2 * Ncnr - 1 Step 2
k = (i + 1) / 2
bA= Tan((pi - IncAgl(k)) / 4)
B(i) = bAmt
Next i

For i = 0 To 2 * Ncnr + 1
Cells(WRow + 9, 3 + 2 * i) = bx(i)
Cells(WRow + 9, 4 + 2 * i) = by(i)
Next i
For i = 1 To 2 * Ncnr - 1 Step 2
Cells(WRow + 10, 3 + i) = B(i)
Next i
End If

End Sub