We help IT Professionals succeed at work.

VB Constants in text strings

SkyGuyDave
SkyGuyDave asked
on
I use Visual Basic for SQL applications.  Most of the queries are dynamic, lengthy, and complex.  In Visual Studio 2005, I was able to construct the SQL statements with immbeded VB constants (eg. vbLf, vbTab).  During debugging, I could then copy the string value and paste it into SQL Management Studio.  The vb constants gave a formatted layout in SQLMS.

As a simple example:
dim strSql as string = "select a, b, c " + vbLf + "from xyz"

In Visual Studio 2010, the vb constants are ignored or replaced with blanks.  As a result, the query in SQL is not formatted at all.  The same occurs when I paste into Notepad.  Therefore, the formatting is being lost during the Visual Studio copy, and not during the paste.  I've tried all variants of the copy.

This isn't a huge problem, but it seems it should be easy to do.  Any suggestions?

Thanks, Dave
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
This may not make any difference but + is used in C# for string concatenation and we use & in VB for concatenation though + works in most cases.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Do you copy from the tool tip that shows the value when debugging? Did you try using the immediate window instead?
Senior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016
Commented:
I had the same problem. Instead of using ? strSQL, use this:

Debug.Print(strSQL)

Author

Commented:
Using Debug.Print() in the Immediate window worked perfectly.  Thanks, emoreau, for the solution.

Too bad it doesn't work from the "Copy" function from the tooltip, as it did in Visual Studio 2005.  That was really easy!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.