1

I have written a Notepad++ Macro that will convert a SQL Query into a Vb string to paste into my VB code.

The principal is that you could just press Ctrl + Shift + E and the macro should convert the SQL line from something like SELECT a FROM b TO "SELECT a FROM b" & vbCrLf & _ and then the cursor should move to the next line.

This is what my Macro looks like:

<Macro name="VB Script" Ctrl="yes" Alt="no" Shift="yes" Key="69">
    <Action type="0" message="2453" wParam="0" lParam="0" sParam="" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
    <Action type="0" message="2451" wParam="0" lParam="0" sParam="" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam='&quot;' />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&amp;" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="v" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="b" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="c" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="r" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="l" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="f" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&amp;" />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam="_" />
    <Action type="0" message="2300" wParam="0" lParam="0" sParam="" />
</Macro>

I have checked with a few different ways and determined that this line will move the cursor one line down:

<Action type="0" message="2300" wParam="0" lParam="0" sParam="" />

The problem is that only on the first line executes the entire macro and moves one line down. But any line after that it doesn't move down a line.

Jacques Koekemoer
  • 1,378
  • 5
  • 25
  • 50
  • I just tried your macro, and it worked perfectly when I used this as the text to process: `SELECT a FROM b` (On four lines). The Ctrl+Shift+E shortcut worked, and also the "Run until the end of file" mode worked too. I'm using NotePad++ 6.8.1. Do you get the same result for *this* set of text? – Sam Nov 08 '16 at 08:23
  • On `SELECT a FROM b` over 4 lines (using Run until the end of file), it stops at the second line. Just using the shortcut key it stops on the second line. I am using version 6.9.2 I wonder if it is because it is trying to auto-complete the word `vbCrLf` on line 2. Because it keeps popping up with that list. – Jacques Koekemoer Nov 08 '16 at 08:37
  • 1
    @Sam I found it. It was as I just thought the Auto Completion. I disabled it by following instructions here: `http://stackoverflow.com/questions/21263705/how-do-i-stop-notepad-from-showing-autocomplete-for-all-words-in-the-file` and now the macro works perfectly. – Jacques Koekemoer Nov 08 '16 at 08:39
  • Wow, thanks! I just tested it with and without auto complete turned on, and when auto complete was turned on, it stopped proceeding to the next line. I'd run into this problem before and hadn't thought it was caused by auto complete. – Sam Nov 08 '16 at 09:06
  • It's probably a good idea to add that as the answer to the question since this could be useful for other people as well. – Sam Nov 08 '16 at 09:08

1 Answers1

1

Turning off Auto Complete could resolve the issue.

To turn off Auto Complete follow the instructions here:

https://stackoverflow.com/questions/21263705/how-do-i-stop-no‌​tepad-from-showing-a‌​utocomplete-for-all-‌​words-in-the-file

It would appear as though NotePad++ stops the execution of a Macro when the auto complete menu pops up.

IE: The Macro executes all the code as it would adding all the letters correctly. Then when it needs to activate the Down Arrow key it still executes the code, but on the dropdown that pops up as opposed to the line where the cursor is located.

Community
  • 1
  • 1
Jacques Koekemoer
  • 1,378
  • 5
  • 25
  • 50