Results 1 to 9 of 9

Thread: [RESOLVED] How can I span faster?

Hybrid View

  1. #1
    New Member
    Join Date
    Mar 2006
    Posts
    1

    Re: How can I span faster?

    Hi,
    that's easy to solve.

    The longer the text (sSpan) the longer the & to sSpan.

    Make chunks and you will see its much faster.

    e.g.


    By Jeanie

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Location
    Alabama
    Posts
    15

    Re: How can I span faster?

    It has to be in chunks of 76 characters though.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: How can I span faster?

    It keeps getting slower because each time you handle strings, you copy memory from place to another. So when the string gets longer it just keeps getting slower as more memory is required to be moved around.

    Easiest method to go around this problem is to first reserve the required amount of memory using String$ and then doing Mid$(dest) = Mid$(source) and you'll be copying the data much faster. You just have to precalculate the final size of the string beforehand, which is as simple as
    NewLength = ((Len(source) \ 76) * 78) + (Len(source) Mod 76)

    Yet another method is to copy the data to byte array and handle the copying that way.

    The most ultimate way you can use in VB6 is to change SAFEARRAYHEADER of an integer array to point to the string and copy data from an integer array to another. Search for SisicM to find a InStrCount function by me that uses this method if interested.

    Pretty much the same technique is used in all of these, precalculate the final size and copy data directly to there.

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Location
    Alabama
    Posts
    15

    Re: How can I span faster?

    Ok, first off, thanks for the reply.

    Secondly, I tried the first method you suggested, but it doesn't seem to be actually moving the data from one string to the next. Here is what I came up with:

    VB Code:
    1. NewLength = ((Len(sLong) \ 76) * 78) + (Len(sLong) Mod 76)
    2.     Dim sSpan As String * NewLength
    3.  
    4.     For i = 1 To NewLength Step lLineLength
    5.         ' collect 75 chars and add a vbCrLf
    6.         Mid$(sSpan, i, 76) = Mid$(sLong, i, 74)
    7.         sSpan = sSpan + vbCrLf
    8.     Next i

    sSpan is supposed to be the final string, and sLong is where it needs to be copied from, but it isn't actually copying it. Any suggestions?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width