Multiple Characters in code

C

Conan Kelly

Hello all,

I would like to know if there is a short hand to repeat characters in code.
For example, if I want to display a message box with text on 2 different
lines I would code it like this:

msgBox "First line of text" & chr(13) & "Second line of text", (options),
(title)

What I like doing is making the first line and second line stand out from
each other by separating them with a blank line:

msgBox "First line of text" & chr(13) & chr(13) & "Second line of text",
(options), (title)

Is there a short hand of repeating the "Carrage Return charater"(chr(13)) so
I don't have to type it twice along with extra "&"? Something like "2 *
(chr(13) &)"

Any help any one can offer will be greatly appreciated,

Conan Kelly
 
B

Bob O`Bob

Conan said:
Is there a short hand of repeating the "Carrage Return charater"(chr(13)) so
I don't have to type it twice along with extra "&"? Something like "2 *
(chr(13) &)"


Not exactly.
But there is the predefined constant vbCr, so you can use "vbCr & vbCr"

Plus, if you're going to be coding it A LOT, you can create your own user-defined
constant. Here's a portion from the declarations section of a BAS module from an
email program of mine, where I defined quite a few such constructed constants
because I use them a lot:

Global Const cDOT = "."
Global Const cLFDOT = vbLf & cDOT
Global Const cCRLFCRLF = vbCrLf & vbCrLf
Global Const cCRLFDOT = vbCrLf & cDOT
Global Const cCRLFDOTDOT = cCRLFDOT & cDOT
Global Const cCRLFDOTCRLF = cCRLFDOT & vbCrLf


Bob
 
A

alpine

Hello all,

I would like to know if there is a short hand to repeat characters in code.
For example, if I want to display a message box with text on 2 different
lines I would code it like this:

msgBox "First line of text" & chr(13) & "Second line of text", (options),
(title)

What I like doing is making the first line and second line stand out from
each other by separating them with a blank line:

msgBox "First line of text" & chr(13) & chr(13) & "Second line of text",
(options), (title)

Is there a short hand of repeating the "Carrage Return charater"(chr(13)) so
I don't have to type it twice along with extra "&"? Something like "2 *
(chr(13) &)"

Any help any one can offer will be greatly appreciated,

Conan Kelly


I use the following....

Public Const vbDblLine As String = vbNewLine & vbNewLine

You then just start typing "vbDbl" and hit the spacebar to let
intellisence fill in the rest for you.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
 
B

BeastFish

VB constants like vbCr and vbCrLf can save you some keystrokes. Also, you
can define your own constants:

Const vbCr2 As String = vbCr & vbCr
MsgBox "line one" & vbCr2 & "line two"
 
J

Jonathan Wood

In addition to the other suggestions you've received, you can also use
something like String(2, vbCr).
 
G

Gale Green

I would like to know if there is a short hand to repeat characters in code.
For example, if I want to display a message box with text on 2 different
lines I would code it like this:

msgBox "First line of text" & chr(13) & "Second line of text", (options),
(title)

What I like doing is making the first line and second line stand out from
each other by separating them with a blank line:

msgBox "First line of text" & chr(13) & chr(13) & "Second line of text",
(options), (title)

Is there a short hand of repeating the "Carrage Return charater"(chr(13)) so
I don't have to type it twice along with extra "&"? Something like "2 *
(chr(13) &)"

Well, vbCr is shorter than Chr$(13). <g>

There's the String$ function but it won't save typing when you're only
talking about two consecutive characters.

String$(2, vbCr) ' 16 chars
vbCr & vbCr ' 11 chars

But it will with three or more...

String$(3, vbCr) ' still 16 chars
vbCr & vbCr & vbCr ' 18 chars

On the other hand, if you're using multiple vbCr characters a lot then
you can use

Private Const vbCr2 As String = vbCr & vbCr
or
Private Const vbCr3 As String = vbCr & vbCr & vbCr

MsgBox "a" & vbCr2 & "b" & vbCr3 & "c"

Gale.
 
B

Bob Butler

Conan Kelly said:
Hello all,

I would like to know if there is a short hand to repeat characters in
code. For example, if I want to display a message box with text on 2
different lines I would code it like this:

msgBox "First line of text" & chr(13) & "Second line of text",
(options), (title)

Apart from the other suggestions you have gotten, the "proper" way to add a
line break is vbCRLF or vbNewLine or Chr$(13) & Chr$(10). Some things will
accept a lone Chr$(13)/vbCR or Chr$(10)/vbLF but the standard end-of-line on
a PC is both characters with the Chr$(13) first. A multiline textbox, for
example, won't show a line break with just Chr$(13).
 
M

Martin

I do the following

msgbox FormatMsg("First line of text\n\nSecond line of
text"),{options},{Caption}

FormatMsg is a simple function I wrote that simply replaces the '\n' with a
chr(13) & chr(10)
Comes in very handy in many situations
 
C

Chad DeMeyer

String(number, character)

The String function syntax has these named arguments:

Part Description
number Required; Long. Length of the returned string. If number
contains Null, Null is returned.
character Required; Variant. Character code specifying the character
or string expression whose first character is used to build the return
string. If character contains Null, Null is returned.


Regards,
Chad
 
A

Adam Clark

How about this,

Make a function or sub that takes two string arguments that feed a msgbox
statement that is already setup. This could give you a great deal of
flexability and make your coding much simpler.

Thanks

Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top