View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
Robert Crandal[_3_] Robert Crandal[_3_] is offline
external usenet poster
 
Posts: 161
Default Fast way to truncate string

"GS" wrote:

Function TruncateString$(sText, sFind, Optional lStart& = 1)
TruncateString = Mid$(sText, lStart, InStr(sText, sFind) - lStart)
End Function


Do you know why I'm getting a "Type mismatch" error with this
code?:

'--------------------
Public Function TruncateString$(sText, sFind, Optional lStart& = 1)
TruncateString = Mid$(sText, lStart, InStr(sText, sFind) - lStart)
End Function
'--------------------
Sub TestTruncate()

Dim i As Integer
Dim sFilename As String

sFilename = "C:\out.txt"
sPhrases = Split("Hello world", "Goodbye world", "Not a good world today")

i = FreeFile()
Open sFilename For Output As #i

Print #i, TruncateString$(sPhrases(0), "world")

Close #i

End Sub