Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default ByRef argument type mismatch (repost)

I get a compile error, ByRef argument type mismatch,
with the following (streamlined) code. How can I fix this?

BTW, Gary, I have tried all variations of the TruncateString()
function that you posted. It still produces the same error.
Hopefully this simplified or stripped down code and help
narrow down the problem.

'--------------------------------------------------------------
Function TruncateString$(sText$, sFind$, Optional lStart& = 1)
TruncateString = Mid$(sText, lStart, InStr(sText, sFind) - lStart)
End Function
'--------------------------------------------------------------
Sub basicTest()
Dim s As String
Dim vData ' variant

s = "Hello world. Be the world. Goodnight world."
vData = Split(s, ".")

MsgBox TruncateString(vData(2), "world")

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default ByRef argument type mismatch (repost)

Hi Robert,

Am Thu, 2 Apr 2015 01:18:39 -0700 schrieb Robert Crandal:

Function TruncateString$(sText$, sFind$, Optional lStart& = 1)


Function TruncateString$(sText, sFind$, Optional lStart& = 1)

your sText is typ variant and not string


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default ByRef argument type mismatch (repost)

"Claus Busch" :

Function TruncateString$(sText$, sFind$, Optional lStart& = 1)


Function TruncateString$(sText, sFind$, Optional lStart& = 1)

your sText is typ variant and not string


Ughh. I swear I tried both variations and it was making errors
both ways.

Now that I removed the "$" from the sText paramater it seems to
be working. Ugh! I swear that I had tried both variations, and it
seemed to be making errors both ways, but now it works.

Thanks Claus (and Gary) for your help on this. Pardon my
newbie ways! 8P



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default ByRef argument type mismatch (repost)

I get a compile error, ByRef argument type mismatch,
with the following (streamlined) code. How can I fix this?

BTW, Gary, I have tried all variations of the TruncateString()
function that you posted. It still produces the same error.
Hopefully this simplified or stripped down code and help
narrow down the problem.

'--------------------------------------------------------------
Function TruncateString$(sText$, sFind$, Optional lStart& = 1)
TruncateString = Mid$(sText, lStart, InStr(sText, sFind) - lStart)
End Function
'--------------------------------------------------------------
Sub basicTest()
Dim s As String
Dim vData ' variant

s = "Hello world. Be the world. Goodnight world."
vData = Split(s, ".")

MsgBox TruncateString(vData(2), "world")

End Sub


CStr(vData(2)) is what the function is expecting...

MsgBox TruncateString(CStr(vData(2)), "world")


While Claus' suggestion handles that you passed a variant where a
string is required is correct. However, I would leave the arg type as
string because the function manipulates strings by design AND name, to
return a string. Mixing data types is going to cause confusion at some
point, and so should be avoided (IMO)!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default ByRef argument type mismatch (repost)

Hi Garry,

Am Thu, 02 Apr 2015 10:32:28 -0400 schrieb GS:

However, I would leave the arg type as
string because the function manipulates strings by design AND name, to
return a string. Mixing data types is going to cause confusion at some
point, and so should be avoided (IMO)!


then he could put in vData by Value instead of reference:

Function TruncateString$(ByVal sText$, sFind$, Optional lStart& = 1)


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default ByRef argument type mismatch (repost)

Robert,
Please use the latest version of the TruncateString$() function that
has the If..Then construct.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default ByRef argument type mismatch (repost)

Hi Garry,

Am Thu, 02 Apr 2015 10:32:28 -0400 schrieb GS:

However, I would leave the arg type as
string because the function manipulates strings by design AND name,
to return a string. Mixing data types is going to cause confusion
at some point, and so should be avoided (IMO)!


then he could put in vData by Value instead of reference:

Function TruncateString$(ByVal sText$, sFind$, Optional lStart& = 1)


Regards
Claus B.


Correct! My bad for not properly converting this from VBS to VB...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default ByRef argument type mismatch (repost)

Properly converted...

Function TruncateString$(ByVal sText$, ByVal sFind$, Optional lStart& =
1)
If InStr(sText, sFind) 0 Then
TruncateString = Mid$(sText, lStart, InStr(sText, sFind) - lStart)
Else
TruncateString = sText
End If
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
"Compile Error: ByRef argument type mismatch" when calling my function from another module ker_01 Excel Programming 2 August 14th 08 03:53 PM
ByRef Argument Type Mismatch Sprinks Excel Programming 5 August 8th 08 04:11 PM
ByRef Argument Type mismatch Tone[_4_] Excel Programming 4 July 3rd 08 02:35 PM
ByRef argument type mismatch when passing dictionary object signon77 Excel Programming 7 January 8th 08 10:03 PM
ByRef argument type mismatch error? sermest Excel Programming 4 June 17th 05 06:50 PM


All times are GMT +1. The time now is 09:12 PM.

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

About Us

"It's about Microsoft Excel"