Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
"Compile Error: ByRef argument type mismatch" when calling my function from another module | Excel Programming | |||
ByRef Argument Type Mismatch | Excel Programming | |||
ByRef Argument Type mismatch | Excel Programming | |||
ByRef argument type mismatch when passing dictionary object | Excel Programming | |||
ByRef argument type mismatch error? | Excel Programming |