Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default mismatch error and Variants


Tony


when you call GetP is the data that you are using to supply to Wrow a
Integer if it is not
you will get a mismath error

eg the following code errors because data in Macro1 is a Long number
and Wrow expecting a Integer number

sub Macro1
dim myLong as Long
myLong = 45
call Macro2(myLong)
end sub

sub Macro2(Wrow as Integer)

mycodehere
end sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default mismatch error and Variants

Yes, WRow is dimensioned as an integer in the subroutine that has the GetP
call. I didn't want to include that entire subroutine as well because it's
also rather long. But it has lines:
Dimm WRow as Integer
Dim AnIBlk as Boolean

That is what is so puzzling to me about all this.

-Tony


"mudraker" wrote:


Tony


when you call GetP is the data that you are using to supply to Wrow a
Integer if it is not
you will get a mismath error

eg the following code errors because data in Macro1 is a Long number
and Wrow expecting a Integer number

sub Macro1
dim myLong as Long
myLong = 45
call Macro2(myLong)
end sub

sub Macro2(Wrow as Integer)

mycodehere
end sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default mismatch error and Variants

Your sub has multiple undeclared variables in it.
You should use "Option Explicit" as the first line of
every module. That forces you to declare all variables and
highlights misspelled variables for you.

I am guessing that your declaration of Wrow as an Integer may be flawed.
In your sub you use this line ... "Dim i, j, k, l As Integer" ...
which results in i, j, k, being declared as Variants and only
l being an integer.
If you did the same thing with Wrow, that is your problem.

In general, avoid the use of Integer as a data type.
The Long data type is preferred. Using an Integer for a row
number variable will cause an error above row ~32700.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"T_o_n_y"
wrote in message
Yes, WRow is dimensioned as an integer in the subroutine that has the GetP
call. I didn't want to include that entire subroutine as well because it's
also rather long. But it has lines:
Dimm WRow as Integer
Dim AnIBlk as Boolean

That is what is so puzzling to me about all this.

-Tony


"mudraker" wrote:


Tony


when you call GetP is the data that you are using to supply to Wrow a
Integer if it is not
you will get a mismath error

eg the following code errors because data in Macro1 is a Long number
and Wrow expecting a Integer number

sub Macro1
dim myLong as Long
myLong = 45
call Macro2(myLong)
end sub

sub Macro2(Wrow as Integer)

mycodehere
end sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default mismatch error and Variants


Tony

Jim is correct if you declared your variables in your macros as you
have in your posted code
Dim i, j, k, l As Integer
It is only the last variable that is declared as a Integer

You need to use
Dim i as Integer
Dim J as Integer
Dim K as Integer

If you modify your declartions as above in all your macros

You can turn on the Option Explicit for all new workbooks & modules by
going to Tools Options Editor Tab Require Variable Declaration

or having the very 1st entry on your modules as
Option Explicit

Using this option saves a lot debugging problems


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default mismatch error and Variants

Thank you, Jim. That really helped.

"Jim Cone" wrote:

Your sub has multiple undeclared variables in it.
You should use "Option Explicit" as the first line of
every module. That forces you to declare all variables and
highlights misspelled variables for you.

I am guessing that your declaration of Wrow as an Integer may be flawed.
In your sub you use this line ... "Dim i, j, k, l As Integer" ...
which results in i, j, k, being declared as Variants and only
l being an integer.
If you did the same thing with Wrow, that is your problem.

In general, avoid the use of Integer as a data type.
The Long data type is preferred. Using an Integer for a row
number variable will cause an error above row ~32700.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"T_o_n_y"
wrote in message
Yes, WRow is dimensioned as an integer in the subroutine that has the GetP
call. I didn't want to include that entire subroutine as well because it's
also rather long. But it has lines:
Dimm WRow as Integer
Dim AnIBlk as Boolean

That is what is so puzzling to me about all this.

-Tony


"mudraker" wrote:


Tony


when you call GetP is the data that you are using to supply to Wrow a
Integer if it is not
you will get a mismath error

eg the following code errors because data in Macro1 is a Long number
and Wrow expecting a Integer number

sub Macro1
dim myLong as Long
myLong = 45
call Macro2(myLong)
end sub

sub Macro2(Wrow as Integer)

mycodehere
end sub


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default mismatch error and Variants

It seems strange to me that you must declare each integer one at a time. But
if that's the way it must be done...

Anyway, thank you for the replies.

"mudraker" wrote:


Tony

Jim is correct if you declared your variables in your macros as you
have in your posted code
Dim i, j, k, l As Integer
It is only the last variable that is declared as a Integer

You need to use
Dim i as Integer
Dim J as Integer
Dim K as Integer

If you modify your declartions as above in all your macros

You can turn on the Option Explicit for all new workbooks & modules by
going to Tools Options Editor Tab Require Variable Declaration

or having the very 1st entry on your modules as
Option Explicit

Using this option saves a lot debugging problems


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535794


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
xpath error? Runtime Error 13 type mismatch Steve M[_2_] Excel Discussion (Misc queries) 0 January 17th 08 01:16 AM
xpath error? Runtime Error 13 type mismatch SteveM Excel Discussion (Misc queries) 1 December 4th 07 09:16 AM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM


All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"