SQL Server Scripts

Development Snippets

Error Handling

Try Catch

                
BEGIN TRY

BEGIN TRANSACTION    
    --Do Work
END TRANSACTION

BEGIN CATCH

    IF (XACT_STATE()) IN (1,-1) 
        ROLLBACK TRAN 

    DECLARE @ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE() ;
    DECLARE @ErrorSeverity INT = ERROR_SEVERITY() ;
    DECLARE @ErrorState INT = ERROR_STATE() ;
    
    RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) ;

END CATCH
        
        


No Sleep

MouseMover

                
Opt("GuiOnEventMode",1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1); no default tray menuitems
#NoTrayIcon
#include 

Global $infolabel
Global $sleepTime
Global $pause = 1

;---------------Tray event values----------------

Global $TRAY_EVENT_SHOWICON         = -3
Global $TRAY_EVENT_HIDEICON         = -4
Global $TRAY_EVENT_FLASHICON        = -5
Global $TRAY_EVENT_NOFLASHICON      = -6
Global $TRAY_EVENT_PRIMARYDOWN      = -7
Global $TRAY_EVENT_PRIMARYUP        = -8
Global $TRAY_EVENT_SECONDARYDOWN    = -9
Global $TRAY_EVENT_SECONDARYUP      = -10
Global $TRAY_EVENT_MOUSEOVER        = -11
Global $TRAY_EVENT_MOUSEOUT         = -12
Global $TRAY_EVENT_PRIMARYDOUBLE    = -13
Global $TRAY_EVENT_SECONDARYDOUBLE  = -14
    
;---------------Build UI----------------
TraySetClick(16)

$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitEvent")

TraySetIcon(@AutoItExe)

TraySetState()
TraySetToolTip("Why work when you can be awesome!")

;---------------Set initial variables----------------

$lastpos = MouseGetPos()
$PreviousSetting = RegRead("HKEY_CURRENT_USER\SOFTWARE\KillSaver\", "Timeout")
If $PreviousSetting <> "" Then
    $sleepTime = $PreviousSetting
Else
    $sleepTime = 1000 * 60 * 1;1 minutes = 1000 * 60 * 1
EndIf


;---------------Main loop----------------

While 1
    $currentpos = MouseGetPos()
   ;Check if current position is the same as the last position, if true move the mouse to the right.
    if $lastpos[0] = $currentpos[0] AND $lastpos[1] = $currentpos[1] then
        MouseMove($currentpos[0] + 50, $currentpos[1], 4)
        
       ;Check to see if the mouse has actually moved, move the mouse to the left if not.
        $newpos = MouseGetPos()
        if $lastpos[0] = $newpos[0] AND $lastpos[1] = $newpos[1] then
            MouseMove($currentpos[0] - 50, $currentpos[1], 4)
        endif
        
       ;Move back to original position so the mouse is in the same place they left it.
        MouseMove($currentpos[0], $currentpos[1], 4)
    EndIF
   ;MsgBox(48,"",$sleepTime)
    Sleep($sleepTime)
    $lastpos = $currentpos
WEnd

Exit

;---------------Functions----------------

;Function for exiting the app
Func ExitEvent()
    Exit
EndFunc

;Close last GUI window
Func OnClose()
    GUIDelete()
EndFunc