help...
text1.text = string(5,vbforums)
result text1.text = vbforumsvbforumsvbforumsvbforumsvbforums
i use string(5,vbforums) but it don't work
anyone can help me :(
Printable View
help...
text1.text = string(5,vbforums)
result text1.text = vbforumsvbforumsvbforumsvbforumsvbforums
i use string(5,vbforums) but it don't work
anyone can help me :(
Either concatenate the string "vbforums" 5 times or get fancy using Mid$()
Code:For I = 1 To 5
theString = theString & "vbforums"
Next
:: or ::
srcString = "vbforums"
iLen = Len(srcString)
theString = Space$(iLen * nrTimesToRepeat)
For i = 0 to nrTimesToRepeat-1
Mid$(theString, i*iLen + 1, iLen) = srcString
Next
Get even fancier using Mid statement. (Mid$ only applies to the function, though the syntax works with both.)
I think we had this wrapped up as a function in Code It Better a while back.Code:srcString = "vbforums"
iLen = Len(srcString)
theString = Space$(iLen * nrTimesToRepeat)
Mid(theString, 1) = srcString
Mid(theString, iLen + 1) = theString ' Believe it! :o)
Edit: Not in CIB. This was discussed here in May '08
The function using Mid as above appeared in a separate thread here in Jan '09
Quote:
Originally Posted by Merri
Consider this possibility:
Code:MyString = "VbForums"
BigString = Space$(Len(MyString) * 5)
For I = 1 To 5 * Len(MyString) Step Len(MyString)
Mid$(BigString, I) = MyString
Next
MsgBox BigString
I was wondering how to do it without coding a loop and came up with this:
Code:Dim strA As String
Dim strB As String
Dim intRepeat As Integer
strA = "VBForums"
intRepeat = 5
strB = String(intRepeat, 0)
strB = Replace(strB, Chr(0), strA)
Debug.Print strB
Good one, Doogle, but loops are rather fast as well.
It would be interesting to see someone test my code against yours with a billion iterations or so. I'm not sure which one is faster.
Logophobic, et al. used to do things like that on occasion. ;)
Replace is much slower, though it is fast enough for practical use. The only benefit is that it can be written as one line: strB = Replace(Space$(Number), " ", strA)
Comparison: "VBForums", repeat 500,000
Mid, as in Merri's function: 11 ms
Loop, a la Code Doc: 27 ms
Replace, one-liner: 3500 ms
Logo
Nice comparison .. :thumb:
Spoo
wow...
thanks for all the reply...
:thumb::thumb::thumb::thumb::thumb:
Damn, that was pretty cool