Re: Does VBscript support " & _" for long strings?



On Thu, 18 Jan 2007 03:27:44 -0600, Anthony Jones <Ant@xxxxxxxxxxxxxxxx> wrote:

It does depend on the actual application. If you are concatenating a set of
constants as in the OP then the above is a fair comparison, although I
suspect a real world requirement would include more than just 3
concatenations and Join would probably overtake direct concatenation fairly
quickly as the number of constants increased.

Interestingly, this does seem to be the case. With 1000 concatenations, the concatenation operator takes over 200 times longer than Join/Array. I imagine that each use of the concatenation operator is creating temporary values and then throwing them away after appending the next value.

If you are concatenating a set of strings retrieved from a function or
expression such as from a field value you would assign each element directly
to an array element. Hence the use of the Array function above adds an
extra copy of each string that would not be present in a real solution..

Assigning a large string to an element in an array apparently is slightly faster than creating the same array using the Array function, but not so much that Array could be making superfluous copies of the string.

Option Explicit

Dim a: a = String(100000000, "a")

Function Prof(f)
Dim start, finish, i, total
total = 0
For i = 0 To 9
start = Timer()
f
finish = Timer()
total = total + finish - start
Next
Prof = total/10
End Function

Sub ProfDim()
Dim aa(0): aa(0) = a
End Sub
WScript.Echo "Dim" & vbTab & Prof(GetRef("ProfDim")) & "s"

Sub ProfArray()
Dim aa: aa = Array(a)
End Sub
WScript.Echo "Array" & vbTab & Prof(GetRef("ProfArray")) & "s"


--
Justin Piper
Bizco Technologies
http://www.bizco.com/
.



Relevant Pages

  • RE: Follow up question. Get value of closed file.
    ... You havve to access each member of the array ... Dim ReturnData as Variant ... SourceSheet As String, _ ... Dim rsData As Object ...
    (microsoft.public.excel.programming)
  • Re: Need help with SeriesCollection Object Please !
    ... Why did you use 4 Elements in your Array and then the use of the Exit ... Function GetSourceSheet(sFmla As String, sWSname, sFile As String) As ... Dim i As Long ... ran my code on certain other charts sometimes it would return ...
    (microsoft.public.excel.programming)
  • Re: Searching for best matches in string query
    ... looped through my recordset as an array counting the matches. ... 'Receives an array to be searched and the string value containing all the ... Dim arrData() ' As String ... Dim iLeftcur, iRightCur, iPivot, iTemp As Long ...
    (microsoft.public.access.queries)
  • RE: ReDim Preserve code almost working
    ... specifying beginning and ending elements. ... SegList will, however, accept a zero-based array (because Option Base 1 does ... Optional iEnd As Long = -1) As String() ... Dim tmp() As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Sorting a variant array
    ... Dim tempList As Variant ... Dim testerList() As String ... Function sortTesters(rangeName As String) ... column range--but even that ends up as a x-rows by 1 column array. ...
    (microsoft.public.excel.programming)