devxlogo

Use the Line Continuation Character with Caution

Use the Line Continuation Character with Caution

Where NOT to use “_”:
1. SQL strings
Why? Because, during debugging, you may have to modify a SQL string because you need to add a field, or remove a field, correct a typo or any number of possibilities. For example, let’s say you have just typed in 50 parameters to get to a particular system state. You press OK and then you get a message box saying “3131 Syntax error in Where clause…”. You look at the SQL and you see an obvious error in a string connected with “_”. You correct the mistake then you get “This action will reset your project, proceed anyway?”. At this point you bang your head against the wall and re-enter the 50 parameters again.
It is much easier to use the following format:

 s = " SELECT * FROM abcTbl " & vbcrlfs = s & " WHERE fieldCDE = 'something' " & vbcrlfs = s & " ORDER BY fieldDEF "

size=3>
This can be modified without the dreaded restart message and if you need to debug this, the formatted text will be readable in the immediate window, whereas continued text will show as a single unformatted long line. There is one caveat, which is that this way makes concatenating a string is less efficient and slower, but this usually doesn’t matter unless you are running it thousands of times. It does not affect SQL performance.
2. Remarks

 'This is a long remark.... more stuff _continuing remark _even more remarks (don't ever do this)

size=3>
Again, if you edit this remark at run time, the system will respond with”This action will reset your project…”. There is absolutely no reason this should occur. Use the block comment with the apostrophe character instead.
Also, you don’t need to continue a line if your screen is wide enough to see the entire line anyway. Since VB now defaults to the MDI IDE, consider returning to the SDI environment. The MDI environment has the peculiarity that if one window is maximized, all are now maximized and none of the hotkeys work (e.g. ctrl-R for the project explorer). Also, the docking feature causes the code window width to be diminished when windows dock side by side. Under menu Tools/Options/Advanced, turn on the “SDI design environment” option, and under the “Docking” tab, turn off ALL the docking. Learn the few basic hotkeys in the SDI environment to be able to navigate much more rapidly and you will have the widest possible editing area (FYI: ctrl-R, ctrl-G, F4, F7, and shift-F7 brings up the project exlorer, immediate window, properties window, form code, and form design windows respectively).
Basically, the “_” character should be used judiciously and not just to make neat columns.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist