View Single Post
  #30   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Fast way to truncate string

"GS" wrote:

Data type was changed from Variant in the original version to
String as last posted (shown here)...


How do I fix this? Most of the data that I'm working with are
strings.
I have tried using different combinations of CStr() or CVar(), and I
even tried changing your function declaration to the following:

Function TruncateString$(sText$ as String, sFind$, '.....)
or
Function TruncateString$(ByVal sText$ as String, sFind$, '.....)

The various errors that I'm getting a
"Invalid procedure call or argument"
"Compile error: ByRef argument type mismatch"

Again, here was the code that I was testing:
'--------------------------------------------------------------------------------
Sub main_test()

Dim sFile1 As String
Dim sFile2 As String
Dim n As Integer
Dim i As Integer
Dim j As Integer
Dim vData ' variant

gsBlankLine = Chr(13) & Chr(13) & Chr(10)
sFile1 = "C:\inp.txt"
sFile2 = "C:\out.txt"

'Group directly into chapters divided by "*" borders
vData = Split(ReadTextFile(sFile1), String(80, "*"))

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

' Scan all narratives
For n = LBound(vData) To UBound(vData)

sClean = Split(vData(n), gsBlankLine)
For j = LBound(sClean) To UBound(sClean)

'
' ******** Error occurs here *********
'
Print #i, TruncateString(sClean(j), "especially so")

Next ' j

Next ' n
Close #i

End Sub


Why are you writing one line at a time? Why not edit the array
elements, then 'dump' its contents into a file in 1 shot???

--
Garry

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