PC Review


Reply
Thread Tools Rate Thread

ByRef Argument Type Mismatch

 
 
Sprinks
Guest
Posts: n/a
 
      8th Aug 2008
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
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      8th Aug 2008
The caller is supplying an integer and the function expects a Single (float).
--
Gary''s Student - gsnu200798
 
Reply With Quote
 
Lars Uffmann
Guest
Posts: n/a
 
      8th Aug 2008
Sprinks wrote:
> 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
 
Reply With Quote
 
Jim Thomlinson
Guest
Posts: n/a
 
      8th Aug 2008
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...
--
HTH...

Jim Thomlinson


"Sprinks" wrote:

> 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

 
Reply With Quote
 
Sprinks
Guest
Posts: n/a
 
      8th Aug 2008
Thanks, Jim.

"Jim Thomlinson" wrote:

> 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...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Sprinks" wrote:
>
> > 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

 
Reply With Quote
 
Sprinks
Guest
Posts: n/a
 
      8th Aug 2008
Thanks, Lars.

"Lars Uffmann" wrote:

> Sprinks wrote:
> > 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ByRef Argument Type mismatch Tone Microsoft Excel Programming 4 3rd Jul 2008 02:35 PM
ByRef Argument Type Mismatch? ArielZusya Microsoft Access VBA Modules 2 6th Jan 2008 05:38 PM
Byref Argument Type Mismatch =?Utf-8?B?QWxleA==?= Microsoft Access VBA Modules 2 25th Oct 2006 09:31 PM
ByRef argument type mismatch Scott Microsoft Access Form Coding 1 15th Jun 2006 07:55 PM
ByRef argument type mismatch Sunny Microsoft Access Getting Started 2 27th Feb 2004 10:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 PM.