Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Repeat

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike H. - 12 Dec 2007 12:45 GMT
In another language I am familiar with if I wanted to express the text
"-----" I could say repeat("-",5).  Is there something similar in VBA?
Trevor Williams - 12 Dec 2007 13:01 GMT
Hi Mike

Try this:

Dim MyString
MyString = String(5, "*")    ' Returns "*****".

> In another language I am familiar with if I wanted to express the text
> "-----" I could say repeat("-",5).  Is there something similar in VBA?
Rick Rothstein (MVP - VB) - 12 Dec 2007 15:56 GMT
Just a quick follow up... the String function will only repeat single
characters (which, of course, is what the OP seems to have asked for), but
if one wanted to repeat, say, the string value "AB" some number of times,
trying this...

   MyString = String(5, "AB")

would result in "AAAAA" being assigned to the variable. The following is one
method to repeat the string "AB", say, five times...

   MyString = Replace(String(5, Chr$(1)), Chr$(1), "AB")

Of course, you could replace the "AB" text string with any string of
characters.

Rick

> Hi Mike
>
[quoted text clipped - 5 lines]
>> In another language I am familiar with if I wanted to express the text
>> "-----" I could say repeat("-",5).  Is there something similar in VBA?
paul.robinson@it-tallaght.ie - 12 Dec 2007 13:02 GMT
> In another language I am familiar with if I wanted to express the text
> "-----" I could say repeat("-",5).  Is there something similar in VBA?

Hi
You could make your own

Public function repeat(inputstring as Variant, repetitions as Long) as
String
Dim temp as String, i as Long
Temp = Cstr(inputstring)  'incase number inputted
For  i = 1 to repetitions
   temp = temp & inputstring
Next i
   repeat = temp
end function

you might need to test unusual inputs.

regards
Paul
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.