Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Continuing VBA statement 1

Status
Not open for further replies.

projecttoday

Programmer
Feb 28, 2004
208
US
This may be a dumb question, but I can't find the answer in the help. How do you continue a statement, specifically one that contains a long character string and you want to maintain spaces.

Dim str as string
str = "the quick brown fox jumped
over the lazy dog"

How to continue the assignment above while maintaining a space after jumped. I tried using _ at the end of the line but it didn't work.
 
How are ya projecttoday . . .

You concatenate using the line continuation character ( a space followed by an underscore character. Giving you:
Code:
[blue]str = "the quick brown fox jumped" & _  
      "over the lazy dog"[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
TheAceMan1 - You missed including the space so it would need to be either this:

Code:
str = "the quick brown fox jumped " & _  
      "over the lazy dog"

or this:

Code:
str = "the quick brown fox jumped" & _  
      " over the lazy dog"


Bob Larson
A2K,A2K3,A2K7,SQL Server 2000/2005,Crystal Reports 10/XI,VB6, WinXP, and Vista
Free Quick Tutorials and Samples:
 
Howdy boblarson . . .

Yeahhhhhhhh . . . but I got the line continuation character right! [thumbsup2] . . . what [blue]projecttoday[/blue] wanted!

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I like to use this concept of adding to the string. This is helpful for long strings with variables in it. Especially helpful with a long sql strings. It allows you to debug the string in parts.

dim str as string
str = "The brown fox jumped "
str = str & "the lazy dog "
'debug.print str
str = str & "on " & date() & ". "
'debug.print str
 
Howdy MajP . . .

Same here! I use it all the time for [blue]formatting the readability of strings & code![/blue] I never have a problem deciphering my code . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
projecttoday . . .

Forgot to mention you can also use the [blue]line continuation character[/blue] to format your code for [blue]easier readability.[/blue] Examples:
Code:
[blue][purple]Non-Formatted:[/purple]
Public Sub AnyRoutine(Mth As Integer, Dy As Integer, Yr As Integer, Wk As Integer, frmName As String, sfrm1Name As String, sfrm2Name As String, sfrm3Name As String, Amt1 As Currency, Tlt As Currency)

[purple]Formatted:[/purple]
Public Sub AnyRoutine(Mth As Integer, _
                      Dy As Integer, _
                      Yr As Integer, _
                      Wk As Integer, _
                      frmName As String, _
                      sfrm1Name As String, _
                      sfrm2Name As String, _
                      sfrm3Name As String, _
                      Amt1 As Currency, _
                      Tlt As Currency)[/blue]
Code:
[blue][purple]Non-Formatted:[/purple]
SQL = "SELECT FirstName, LastName, Initial, Address From tblClients WHERE [LastName] Like '*Ace*';"

[purple]Formatted:[/purple]
SQL = "SELECT FirstName, LastName, Initial, Address " & _
      "From tblClients " & _
      "WHERE [LastName] Like '*Ace*';"[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top