Public Function Replicate10(ByVal lNumber&, sPattern$) As String ' by Marzo Junior, marzojr@taskmail.com.br, 20020527 ' Based on Replicate09 by by Mike Peterson, mpeterson1200@yahoo.com, 20010910 If lNumber > 0 Then Dim i&, lPointer& lPointer = Len(sPattern) Select Case lPointer Case Is > 1 'Contrary to Mike's code, we NEED to do this here: 'Allocate String Buffer Replicate10 = StringHelpers.SysAllocStringLen(ByVal 0&, lNumber * lPointer) 'Check the highest bit for the While...Wend loop bellow, as well 'as if there is any leftover that needs recursion. We use lNumber 'to store the remainder, as it is one less variable. This is why 'we had to allocate the string buffer above. If lNumber And &H7FFFFF00 Then If lNumber And &H7FFF0000 Then If lNumber And &H40000000 Then lNumber = lNumber Xor &H40000000 i = 30 ElseIf lNumber And &H20000000 Then lNumber = lNumber Xor &H20000000 i = 29 ElseIf lNumber And &H10000000 Then lNumber = lNumber Xor &H10000000 i = 28 ElseIf lNumber And &H8000000 Then lNumber = lNumber Xor &H8000000 i = 27 ElseIf lNumber And &H4000000 Then lNumber = lNumber Xor &H4000000 i = 26 ElseIf lNumber And &H2000000 Then lNumber = lNumber Xor &H2000000 i = 25 ElseIf lNumber And &H1000000 Then lNumber = lNumber Xor &H1000000 i = 24 ElseIf lNumber And &H800000 Then lNumber = lNumber Xor &H800000 i = 23 ElseIf lNumber And &H400000 Then lNumber = lNumber Xor &H400000 i = 22 ElseIf lNumber And &H200000 Then lNumber = lNumber Xor &H200000 i = 21 ElseIf lNumber And &H100000 Then lNumber = lNumber Xor &H100000 i = 20 ElseIf lNumber And &H80000 Then lNumber = lNumber Xor &H80000 i = 19 ElseIf lNumber And &H40000 Then lNumber = lNumber Xor &H40000 i = 18 ElseIf lNumber And &H20000 Then lNumber = lNumber Xor &H20000 i = 17 ElseIf lNumber And &H10000 Then lNumber = lNumber Xor &H10000 i = 16 End If Else If lNumber And &H8000& Then lNumber = lNumber Xor &H8000& i = 15 ElseIf lNumber And &H4000& Then lNumber = lNumber Xor &H4000& i = 14 ElseIf lNumber And &H2000& Then lNumber = lNumber Xor &H2000& i = 13 ElseIf lNumber And &H1000& Then lNumber = lNumber Xor &H1000& i = 12 ElseIf lNumber And &H800& Then lNumber = lNumber Xor &H800& i = 11 ElseIf lNumber And &H400& Then lNumber = lNumber Xor &H400& i = 10 ElseIf lNumber And &H200& Then lNumber = lNumber Xor &H200& i = 9 ElseIf lNumber And &H100& Then lNumber = lNumber Xor &H100& i = 8 End If End If Else If lNumber And &H80& Then lNumber = lNumber Xor &H80& i = 7 ElseIf lNumber And &H40& Then lNumber = lNumber Xor &H40& i = 6 ElseIf lNumber And &H20& Then lNumber = lNumber Xor &H20& i = 5 ElseIf lNumber And &H10& Then lNumber = lNumber Xor &H10& i = 4 ElseIf lNumber And &H8& Then lNumber = lNumber Xor &H8& i = 3 ElseIf lNumber And &H4& Then lNumber = lNumber Xor &H4& i = 2 ElseIf lNumber And &H2& Then lNumber = lNumber Xor &H2& i = 1 Else lNumber = 0 'The following is not needed: 'i = 0 End If End If 'Store the pointer: Dim lptr As Long lptr = StrPtr(Replicate10) lPointer = lPointer * 2& '** Unicode=2 bytes 'Do first CopyMem kernel.MoveMemoryFromStr ByVal lptr, sPattern, ByVal lPointer 'Here we decrease i until it reaches 1, while in the original, 'Mike increased i until 2^i <= lNumber. It is easy to see why 'this way is much faster. While i > 0 kernel.MoveMemoryFromStr ByVal lptr + lPointer, Replicate10, ByVal lPointer lPointer = lPointer + lPointer: i = i - 1 Wend 'If lNumber was not a power of 2, we'll have to recursively catch the rest. If lNumber Then Dim s$ s = Replicate10(lNumber, sPattern) 'Recursion... 'Last CopyMem kernel.MoveMemoryFromStr ByVal lptr + lPointer, s, ByVal LenB(s) End If Case 1 Replicate10 = String$(lNumber, sPattern) End Select End If End Function