ByRef Argument Type Mismatch

  • Thread starter Thread starter Sprinks
  • Start date Start date
S

Sprinks

Excel 2003 SP3, Windows XP 5.1 SP3

The following call is generating the subject error, highlighting intRow.
Can anyone explain it to me?

....Calling procedure
strTag = Trim(ActiveControl.Tag)
intRow = Int(strTag)
ActiveSheet.Shapes("R" & strTag) = _
Round(GetMeansResult(intRow, Val(ActiveSheet.Shapes("txt" &
strTag)), 0))

....GetMeansResult function

Function GetMeansResult(Index As Integer, X As Single)

Thank you.

Sprinks
 
The caller is supplying an integer and the function expects a Single (float).
 
Sprinks said:
Function GetMeansResult(Index As Integer, X As Single)

Change that to

Function GetMeansResult(ByVal Index As Integer, ByVal X As Single)

and you're fine.

It's an annoying and most idiotic behaviour of VB to automatically
assume (and demand) all parameters to a function or sub to be passed by
reference, unless defined as ByVal.

HTH,

Lars
 
strTag is a string. The Int function expects a number and it will return the
integer potion of that number. As a guess you are looking for the CInt
function which takes a string argument and coerces it to an integer. CLng
might be more approproate as it returns a long which is generally speaking
more efficient and less prone to failure...
 
Thanks, Jim.

Jim Thomlinson said:
strTag is a string. The Int function expects a number and it will return the
integer potion of that number. As a guess you are looking for the CInt
function which takes a string argument and coerces it to an integer. CLng
might be more approproate as it returns a long which is generally speaking
more efficient and less prone to failure...
 
Thanks, Lars.

Lars Uffmann said:
Change that to

Function GetMeansResult(ByVal Index As Integer, ByVal X As Single)

and you're fine.

It's an annoying and most idiotic behaviour of VB to automatically
assume (and demand) all parameters to a function or sub to be passed by
reference, unless defined as ByVal.

HTH,

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top