Running single Query in SSMS2017 using AutoHotKey - ssms

I've been trying to get my AHK-Script running in SSMS2017 to execute a single (multi-line) SQL Statement (similar to Ctrl+Enter in SQL Developer).
The idea is that I search for the last (with respect to the last caret position) ";" in my code and highlight the text until the next one and then execute it with F5.
So far my script looks like that:
^ENTER::
CoordMode, Caret, Screen
CoordMode, Mouse, Screen
send ^f
sendraw `;
send {Enter}
send {Esc}
send +{F3}
send {Right}
X1 = A_CaretX
Y1 = A_CaretY
send {F3}
send {Right}
X2 = A_CaretX
Y2 = A_CaretY
MouseClickDrag, Left, X1,Y1,X2,Y2, 100
send {F5}
return
which in my opinion at least syntactically should work. But it doesn't. Apparently because A_CaretX and A_CaretY seem to be empty (I've let AHK output them to me and they are blank). Does anyone know a solution to this problem?

A_CaretX and A_CaretY doesn't work in SQL Server Management Studio because the Query window is not a normal Textbox control, and so you will never be able to get the information using the Carets.
A different way to do it is to copy all the text from the query window, parse it, and loop through the parsed info, pasting and running each parsed text.
^ENTER::
Send ^a
Send ^c
ClipWait 1 ; Wait for clipboard to be filled
Queries := ClipBoard
Loop, parse, Queries, ";"
{
Send ^a
Clipboard := A_LoopField
Send ^v
Sleep 100
Send {F5}
Sleep 1000 ; wait 1 second for query to finish
}
;Replace the text with the original text
Clipboard := Queries
Send ^a
Send ^v
Return

Related

How to send a new line without using `n `r? without an enter

i know that n means "ENTER", but when i'm using n, i dont want to press enter. I just want to put the text in a new line, but what "n" does, it puts in a new line but it also press enter.. i don't want to press enter...
For example
::pergunta::Hello, n How are you? n what are you doing? n bye...
How can i fix that issue?
First, you need to determine what keystrokes your application uses for this purpose, and then you can implement that in Autohotkey.
For example, in Excel, multiple lines of text can be typed into a single cell by pressing ALT-ENTER at the end of each line (instead of ENTER).
So, the following AutoHotkey script would work for Excel:
:X:pergunta::Send, Hello,!{Enter}How are you?!{Enter}what are you doing?!{Enter}bye...
The ":X:" at the beginning means "run a script", which in this case is the "Send" command. The !{Enter} part means ALT-ENTER.
You might also want to use SetKeyDelay to speed up the typing of text:
SetKeyDelay, 0
:X:pergunta::Send, Hello,!{Enter}How are you?!{Enter}what are you doing?!{Enter}bye...

Embed console in form

TL;DR:
Is there a way to embed a console inside a form, so it becomes a part of it?
Scenario:
I am writing a chat-application with client, server and database using Windows Forms in VB.NET. The server should log all communication it has with clients in a textbox.
The Problem:
So far that would not be a problem - If there wasn't a maxlength for strings! I expect this server to almost never stop (Okay, there is always some point where it does.. but lets ignore that). So if i go for Textbox1.Text &= vbnewline & "Something" it will some day reach this length and run into an exception each time something is about to be logged. I also don't want to just remove the first characters of the string.
My Idea for a solution:
My idea for a work around: Use a console instead of a simple textbox and embed it into the form, so it becomes a part of it. Is there a simple way to do that? By simple I mean that I should have to write thousands of lines of code to achieve that goal.
I am open minded for different ideas and ways to do so as well.
Why not just log your chat to file (you could create a file per day)?
Dim filename = String.Format("C:\Temp\{0:yyyy-MM-dd}-log.txt", DateTime.Now)
My.Computer.FileSystem.WriteAllText(filename, "line of text", True)
Then to display it - use a ListBox and append each new line to the end of the listbox? Each time you append, you could check how many items are in the listbox and remove the first 100 if you are over 1000 as an example.

Autohotkey: how to determine clipboard buffer contents size

I have a script that scrapes a certain portion of the screen and acquires about 100-200 bytes long text in to the clipboard. Sometimes, due to web server timeout or missing CSS definitions etc, the page doesn't render correctly and the sane mouse drag, selects a much larger amount of text and copies it to the clipboard.
I want to be able to notice this situation and scrap the clipboard contents and run my script again, till it is at the expected size of 100-200 bytes. Finally abort the script if large buffer keeps happening for certain number of times.
I have the logic for it but only thing I am not able to figure out the clipboard size and how to get it inside AHK script. Is there a predefined variable for it ? Or is there another, more complicated method ? What comes to mind is to paste the contents into notepad and save it. Then look at the file size, but it is very convoluted. I want something without a disk write operation.
Any ideas ? I saw the strlen command but not sure how to use it...
If it is text in your clipboard this works:
ClipSize := strlen(clipboard)
Example Script
sClip:=GetClipboardSize(Clipboard)
sClip_a:=GetClipboardSize(ClipboardAll)
MsgBox Clipboard Size: %sClip%`nClipboardAll Size: %sClip_a%
GetClipboardSize(c) {
if (!s:=strlen(c)) {
tmp:=A_temp "\clipboardsize_" A_TickCount "~~tempfile~~.tmp"
FileDelete,%tmp%
FileAppend,%ClipboardAll%,%tmp%
FileGetSize,s,%tmp%
FileDelete,%tmp%
}
return s
}

Send contents of clipboard as keystrokes in AutoHotkey

I'm looking for a way to send the contents of the clípboard as key output. E.g. if the clipboard says "123456789" I want the keys 1-2-3-4-5-6-7-8-9 sent to the keyboard input.
I've tried:
SetWinDelay 100
SetKeyDelay 0
^f::
Send %clipboard%
return
To map the 'clipboard paste' to ctrl+f, but it is just literally pasting '%clipboard%'
SendRaw %clipboard%
Did the trick

Crystal Reports Cutting Off Text in PDF

I found this post on Crystal Reports Cutting Off Text in PDF, but it didn't solve my problem.
I have a Crystal Report that contains a field within a text object (to control line spacing) and has "can grow" selected. When I export the Crystal Report to a PDF there are instances when the text is cut off.
In this example the text is being cut off on the right side, but in some cases, when the text consists of many lines, the bottom part of the last line will be partially cut off.
I am using Crystal Reports that is bundled with Visual Studio 2008. The text area has "can grow" checked, the font is set to Helvetica LT Condensed, bold 14, and the line spacing is set to 0.75 times normal.
Anyone have any thoughts on how can I fix this?
I have run into this as well - Crystal seems a little confused about where the text box borders are. I suggest adding a small right indent to the text box (right click on the text box, select 'Format Object', select the 'Paragraph' tab, and enter small numbers (maybe .2 or so) into the Right text box. This should help with the right margin.
As for the bottom cut-off, there is no margin that you can add. Can you add a line break to the end of your text as it comes from the db? Or, you could try a formula field to add the line break:
{table_name.field_name} + chr(13) + chr(10)
I think I've found out the problem. The bounding subreport width was smaller than the width of the field object. Adjusting it's width fixed the truncation occurring on the right-hand side.
On a side note, text being truncated on the bottom seems to be a result of adjusting the line-spacing too small. if you set the line spacing as a multiple of the original text point size and make it too small, the bottom part of the line is truncated. I changed this to "exact" and entered a specific point size (e.g line spacing of 18 pt. for my 16 pt. text) and this seemed to solve the problem. If the line spacing is too small it seems that Crystal masks off the bottom part of the text.
Right click on the text field
Select Common Tab
In the Horizontal Alignment section I changed it to "Justified".
This adjusted the text to span properly and not cut off prematurely when using Can Grow.
I tried this and it solved this issue.
Try to do following :
Text Object > Right Click > Format Text > Border Tab
Change Line Style : Right/Left/Top/Bottom as single and change color to White.
I experienced this problem when I updated a Stored procedure. I changed the Description field that I was pulling onto the report from a VARCHAR(100) to a VARCHAR(150) inline with a requested change. The Crystal report in preview mode had stored old limit of 100 characters and was truncating the label. This was rectified when I verified the database again.
Database Tab -> Verify Database
I too discovered this too. Only happened in HTML view. I did a few things which for 3 blocks I needed to do different and tried numerous scenarios to choose the best to go with.
- Format text from left justufied to justified
- Grip the right edge of the text box and pulled it in a tick from the right margin
- Switched the font from Times New Roman to another (wierd)
- Exporting from BI LP as a CR RPT and exported from the CR 2013 client to PDF
- Change font size - We had an "and / or" midline and changed it to "and/or"
We went with the justified alignment since it was close to a full line and didn't look different than original.
Lots of wierd workarounds that rectified it. To me, it's indicating a system upgrade glitch in the report.
Hope what I found helps others.
If you tried all the methods and still not working, you can try the following:
Local StringVar inString := 'Your text string here.......';
Local NumberVar strLen := Length (inString);
Local StringVar result := "";
Local NumberVar maxLen := 45; // adjust the length of text per line
Local NumberVar idx := 0;
Local NumberVar proceed := 0;
While strLen > maxLen Do
(
proceed := 1;
idx := maxLen;
While (mid(inString,idx,1) <> " " and idx > 1) Do
(
idx := idx -1;
);
if (idx = 1) then
result := result + mid(inString,1,maxlen) + chr(10)
else
(
result := result + mid(inString, 1, idx-1)+ chr(10);
strLen := strLen-idx;
inString := mid(inString, idx+1, strLen)
)
);
if proceed = 1 then
(
result := result + inString
)
else
(
result := inString
);
result
In one environment with Crystal Reports it was a help for us to set the registry key: ForceLargerFonts = 0
How to find?
For 64 bit version of MS Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SAP BusinessObjects\Suite XI 4.0\Crystal Reports\Export\PDF
For 32 bit version of MS Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Suite XI 4.0\Crystal Reports\Export\PDF
Please see also the following solution at
https://apps.support.sap.com/sap/support/knowledge/public/en/0001835763
This is a difficult problem that you have to attack from 3 different fronts:
Software Hot Fix
Default Printer
Form Authoring
Software Hot Fix: You'll need to download the CRRuntime that includes Hot Fix 20. This Hot Fix addresses truncation problems when making a PDF. You can find it at http://downloads.businessobjects.com/akdlm/crnetruntime/clickonce/CRRuntime_64bit_13_0_20.msi
Default Printer: The printer you use when authoring a report must match a printer where you are rendering a report. On our servers, there are no printers installed except the Microsoft XPS Document Writer. Be sure to select that as you default printer when writing the report.
Form Authoring: When you add a database field to your report, don't drag it from the field explorer onto the design surface. First insert a text object onto the design surface. When you've positioned and resized the Text Object the way you like it, drag the database field onto the Text Object. You'll see the name of the database item in curly braces appear in the Text Object. For whatever reason, the database field will wrap better when it is enclosed by a Text Object.
This got me literally stressed for a whole night!!
What worked for me was this:
if you are using crystal reports with dataset (linked to a dataset),most likely you changed the length of the field in the database. so if the length was 10 and you adjust to 20 for instance, no matter what you do, the report is reading the "Old" dataset with the field of length 10 characters and truncating it at 10 (I don't know why it did that)...believe it or not I just copied the query from my "Old" dataset,created a new dataset and VOILA!!! it worked like charm...