Line Continuation issue

B

Bishop

What am I doing wrong? Here is the line of code:

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. Have you
completed "" ""PFs?", vbYesNo, "Completed PFs")

But I want to use ' _' to continue the phrase on the next line but when I do
this:

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. _
Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

I keep getting "Expected: list separator or )"
 
J

Jacob Skaria

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
J

Jacob Skaria

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
J

Jarek Kujawa

use

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." &
vbNewLine & "Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
J

Jarek Kujawa

use

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." &
vbNewLine & "Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
D

Don Guillett

prompt Required. String expression displayed as the message in the
dialog box. The maximum length of prompt is approximately 1024 characters,
depending on the width of the characters used. If prompt consists of more
than one line, you can separate the lines using a carriage return character
(Chr(13)), a linefeed character (Chr(10)), or carriage return – linefeed
character combination (Chr(13) & Chr(10)) between each line.

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." _
& Chr(10) & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
D

Don Guillett

prompt Required. String expression displayed as the message in the
dialog box. The maximum length of prompt is approximately 1024 characters,
depending on the width of the characters used. If prompt consists of more
than one line, you can separate the lines using a carriage return character
(Chr(13)), a linefeed character (Chr(10)), or carriage return – linefeed
character combination (Chr(13) & Chr(10)) between each line.

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." _
& Chr(10) & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")
 
J

Jacob Skaria

Oops..Use Vbcr Or VbLF for carriage return

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & vbCrLf & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

If this post helps click Yes
 
J

Jacob Skaria

Oops..Use Vbcr Or VbLF for carriage return

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & vbCrLf & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

If this post helps click Yes
 
J

Jacob Skaria

Dear Bishop

A small suggestion. When you have bigger text to be displayed use a variable
to build the message before display..something like..the below

Dim intCount As Integer
Dim strMsg As String

strMsg = "You have " & intCount & " PFs loaded in the Tally Sheet."
strMsg = strMsg & vbCrLf & vbCrLf & " Have you completed " & intCount & "
PFs?"

If MsgBox(strMsg, vbYesNo + vbDefaultButton2, " Completed PFs") <> vbYes _
Then Exit Sub


If this post helps click Yes
 
J

Jacob Skaria

Dear Bishop

A small suggestion. When you have bigger text to be displayed use a variable
to build the message before display..something like..the below

Dim intCount As Integer
Dim strMsg As String

strMsg = "You have " & intCount & " PFs loaded in the Tally Sheet."
strMsg = strMsg & vbCrLf & vbCrLf & " Have you completed " & intCount & "
PFs?"

If MsgBox(strMsg, vbYesNo + vbDefaultButton2, " Completed PFs") <> vbYes _
Then Exit Sub


If this post helps click Yes
 
R

Rick Rothstein

Text strings constants (which are defined by a starting and ending quote
mark) must all appear on the same line. When you put your line continuation
character in, you left the quote marks unbalanced on the original line (no
ending quote mark) and on the newly created line (no starting quote mark).
You *cannot* simply put them in like this though...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

because VB will not know what to do with the two parts. It would be like if
you wrote this line of code...

StrVar = "First part of sentence" "Next part of sentence"

To handle both of these, you would need an ampersand between the two text
string constants in order to concatenate them together. So, your original
line line of code could have been written this way...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. " & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Doing it this way, however, will just link the two text string constants
together as if they had been written in a single line. You would do it this
way in order to "neaten" up your code on the screen in order that *you*
could more read it more easily (as opposed to having a long text string
possibly trail off the screen because it is too long to display within the
given the code window's width. To do what I think you asked... display the
two individual text string constants on two separate lines within the
MessageBox... you have to tell VB to put a line separating character between
them. The help files say that you can use a Line Feed character, a Carriage
Return or a combination of Line Feed and Carriage Return characters (in that
order). VB has predefined characters for these line separating characters
and they are, in the same order I listed them in, vbLf, vbCr and vbLfCr. VB
also has an alternative constant for that last one... vbNewLine. So, using
vbLf as the separator, your original code line would be...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & vbLf & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Now, when VB creates the MessageBox message, it will display the two text
string constants on separate lines.
 
R

Rick Rothstein

Text strings constants (which are defined by a starting and ending quote
mark) must all appear on the same line. When you put your line continuation
character in, you left the quote marks unbalanced on the original line (no
ending quote mark) and on the newly created line (no starting quote mark).
You *cannot* simply put them in like this though...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

because VB will not know what to do with the two parts. It would be like if
you wrote this line of code...

StrVar = "First part of sentence" "Next part of sentence"

To handle both of these, you would need an ampersand between the two text
string constants in order to concatenate them together. So, your original
line line of code could have been written this way...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. " & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Doing it this way, however, will just link the two text string constants
together as if they had been written in a single line. You would do it this
way in order to "neaten" up your code on the screen in order that *you*
could more read it more easily (as opposed to having a long text string
possibly trail off the screen because it is too long to display within the
given the code window's width. To do what I think you asked... display the
two individual text string constants on two separate lines within the
MessageBox... you have to tell VB to put a line separating character between
them. The help files say that you can use a Line Feed character, a Carriage
Return or a combination of Line Feed and Carriage Return characters (in that
order). VB has predefined characters for these line separating characters
and they are, in the same order I listed them in, vbLf, vbCr and vbLfCr. VB
also has an alternative constant for that last one... vbNewLine. So, using
vbLf as the separator, your original code line would be...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & vbLf & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Now, when VB creates the MessageBox message, it will display the two text
string constants on separate lines.
 

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