Jump to content
Sign in to follow this  
Wombat

MS SQL assistance

Recommended Posts

Wombat

Ok so here is the background info to the task I'm working on:

I'm on windows7 x64

I'm trying to connect to a MS SQL server 2008 r2

After connecting I need to execute a query that will run a stored procedure

Then I need to close the connection.

I just dug into my admin tools and found out that I do NOT have an ODB driver installed.

I had found some code here on the forum and attempted to edit it to my requirements and I FAILED.

I'm in need of help to review the code snippet and produce a solution.

here is my SQL code ( the _SQLCommand() runs the connect, query, and shutdown commands):

Func _SQLConnect($sServer, $sDatabase, $fAuthMode = 0, $sUsername = "", $sPassword = "", $sDriver = "{SQL Server}")
    Local $sTemp = StringMid($sDriver, 2, StringLen($sDriver) - 2)
    Local $sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $sVal = RegRead($sKey, $sTemp)
    If @error or $sVal = "" Then Return SetError(2, 0, 0)
    $oConn = ObjCreate("ADODB.Connection")
    If NOT IsObj($oConn) Then Return SetError(3, 0, 0)
    If $fAuthMode Then $oConn.Open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";")
    If NOT $fAuthMode Then $oConn.Open("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase)
    If @error Then Return SetError(1, 0, 0)
    Return $oConn
EndFunc   ;==>_SQLConnect

Func _SQLCommand()
    Local $cQ=Chr(39)
    Local $Comma=Chr(44)
    Local $SQLcon=_SQLConnect("mySERVER", "myDB", Default, "me", "abc123", Default)
    If @error Then MsgBox(0, "ERROR", @error)
    MsgBox(0, "", "sp_insert_researchdev " & $cQ & $JOB[0] & $cQ & $Comma & " " & $cQ & $JOB[1] & $cQ & $Comma & " " & $cQ & $JOB[2] & $cQ & $Comma & " " & $cQ & $JOB[3] & $cQ & $Comma & " " & $cQ & $t & $cQ)
    _SQLQuery($SQLcon, "sp_insert_researchdev " & $cQ & $JOB[0] & $cQ & $Comma & " " & $cQ & $JOB[1] & $cQ & $Comma & " " & $cQ & $JOB[2] & $cQ & $Comma & " " & $cQ & $JOB[3] & $cQ & $Comma & " " & $cQ & $t & $cQ)
    If @error Then MsgBox(0, "ERROR", @error)
    _SQLDisconnect($SQLcon)
    If @error Then MsgBox(0, "ERROR", @error)
EndFunc

Func _SQLQuery($oConn, $sQuery)
    If IsObj($oConn) Then Return $oConn.Execute($sQuery)
    Return SetError(1, 0, 0)
EndFunc ;==>_SQLQuery

Func _SQLDisconnect($oConn)
    If NOT IsObj($oConn) Then Return SetError(1, 0, 0)
    $oConn.Close
    Return 1
EndFunc   ;==>_SQLDisconnect

I attempted to install a ODB driver but that did not help any

I acquired help from my systems admin in creating the stored procedure and the query, we tested it outside of autoit and it succesffuly excuted.

The code above is erroring at

Local $sKey = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $sVal = RegRead($sKey, $sTemp)
Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Share this post


Link to post
Share on other sites
Wombat

Alright, so I've successfully pushed test data to the table. But I'm having trouble pushing the actual live data.... So I've narrowed it down to my string formatting...

if anyone can please help lol

here's the code in it's entirety:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Users\Jniswonger\Workshop\Lab\test_res\SET_ico.ico
#AutoIt3Wrapper_Outfile=SET.exe
#AutoIt3Wrapper_Res_Fileversion=2.0.1.5
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
;~ #include <SQLite.au3>
;~ #include <SQLite.dll.au3>
#include <Date.au3>
#include <_sql.au3>
;~ #include <MSSQL.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <ComboConstants.au3>
#include <ScreenCapture.au3>
#include <StaticConstants.au3>
#include <GUIListView.au3>
;##################################
; Options
;##################################

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnEsc", 1)
Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 1)
Global Const $SYSTEMDRIVE = EnvGet('systemdrive')
Global $ABCData, $ReadData1, $ReadData2, $ReadData3, $ReadData4, $ReadData5, $ReadData6, $ReadData7, $ReadData8, $ReadData9

HotKeySet("^d", "_DevMode")

_ScreenGrab();Screen Shot
_ABCReader()

;##################################
; Script
;##################################

Global $Current = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "versioninfo", "version", Default)
Global $Srv = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "system", "serverlocal", Default)
Global $Available = IniRead($Srv & "Users$\Jniswonger\SET\Ctrl.ini", "versioninfo", "version", Default)
Global $Dev = False
Global $DevLabelNote
Global $KEYraw = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "system", "devkey", Default)
Global $KEY = StringTrimRight($KEYraw, 2)
Global $SourceUT = $Srv & "Departmental Shares\UpdateTool\"
Global $Preview = $SYSTEMDRIVE & IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "system", "imgprev", Default)
Global $SETComments
Global $IPDetails = _IPDetails()
Global $RD_Job_TIme, $timer, $Secs, $Mins, $Hour, $Time, $JOB[4], $SQL_data

;###################################
;~ EMAIL DATA
;###################################


Global $SETSmtpServer = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "SmtpServer", Default) ; address for the smtp-server to use - REQUIRED
Global $SETFromName = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "FromName", Default) ; name from who the email was sent
Global $SETFromAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "FromAddress", Default) ; address from where the mail should come
Global $SETToAddress
;~ =IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "ToAddress_mi", Default)
Global $SETSubject = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Subject", Default) ; subject from the email - can be anything you want it to be
Global $SETAttachFiles = $SYSTEMDRIVE & IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "AttachFiles", Default) ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
Global $SETCcAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "CcAddress", Default) ; address for cc - leave blank if not needed
Global $SETBccAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "BccAddress", Default) ; address for bcc - leave blank if not needed
Global $SETImportance = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Importance", Default) ; Send message priority: "High", "Normal", "Low"
Global $SETUsername = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Username", Default) ; username for the account used from where the mail gets sent - REQUIRED
Global $SETPassword = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Password", Default) ; password for the account used from where the mail gets sent - REQUIRED
Global $SETIPPort = Number(IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "IPPort", Default)) ; port used for sending the mail
Global $SETssl = Number(IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "SSL", Default)) ; enables/disables secure socket layer sending - put to 1 if using httpS


#region GUI
$mGUI = GUICreate("Storm Error Tool", 582, 582, Default, Default)
;~ GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUISetOnEvent($GUI_EVENT_CLOSE, "MainGUIClose")

$Menu1 = GUICtrlCreateMenu("System")
$MenuItem1 = GUICtrlCreateMenuItem("Settings", -1)
GUICtrlSetOnEvent(-1, "_settings")
$MenuItem2 = GUICtrlCreateMenuItem("Reset", $Menu1)
GUICtrlSetOnEvent(-1, "_Reset")
$MenuItem3 = GUICtrlCreateMenuItem("", $Menu1)
$MenuItem4 = GUICtrlCreateMenuItem("Close", $Menu1)
GUICtrlSetOnEvent(-1, "MainGUIClose")
$MenuItem4 = GUICtrlCreateMenuItem("R/D Tracker", -1)
GUICtrlSetOnEvent(-1, "_RD_show")

$Group1 = GUICtrlCreateGroup("Comments", 8, 296, 305, 273)

Global $mCmntBox = GUICtrlCreateEdit("", 24, 384, 273, 169, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL))
GUICtrlSetState(-1, @SW_DISABLE)
GUICtrlSetData(-1, "")

Global $mErrorCombo = GUICtrlCreateCombo("", 40, 336, 241, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup("Send / Cancel", 328, 352, 241, 217)

$bSend = GUICtrlCreateButton("SEND", 360, 392, 177, 57)
GUICtrlSetOnEvent(-1, "_SendEmail")

$bCancel = GUICtrlCreateButton("CANCEL", 360, 480, 177, 57)
GUICtrlSetOnEvent(-1, "MainGUIClose")

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group3 = GUICtrlCreateGroup("Preview", 328, 54, 241, 297)

$Pic1 = GUICtrlCreatePic($Preview, 336, 88, 225, 217)

$Button3 = GUICtrlCreateButton("VIEW", 400, 312, 105, 33)
GUICtrlSetOnEvent(-1, "_vPrev")

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group4 = GUICtrlCreateGroup("Recipient", 8, 230, 305, 57)

Global $RecipCombo = GUICtrlCreateCombo("", 56, 256, 209, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Material Issue|TimeKeep|IT Dept", "")

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Label1 = GUICtrlCreateLabel("This program allows you to report errors or issues in work orders.", 20, 40, 304, 150)

Global $SETIDfield = GUICtrlCreateInput("", 144, 180, 129, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER))

$Label2 = GUICtrlCreateLabel("Employee ID", 40, 185)

$hDummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "_SetCom")

GUISetState(@SW_SHOW)
#endregion GUI

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Global $SEToMyRet[2]
Global $SEToMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

If FileGetVersion("C:\SET\SET.exe")<>FileGetVersion("\\fs01\Users$\jniswonger\SET\SET.exe") Then Run("C:\SET\SETup.exe")
While 1

Sleep(100)
WEnd

Func _DevMode()
    Local $DevReq
    If $Dev = False Then
        $DevReq = InputBox("Arm Developer Mode", "To enable Dev Mode please enter the required credentials", "", "*")
        If $DevReq = $KEY Then
            MsgBox(0, "Developer Mode activated", "To disable developer mode press Ctrl+D", 10)
            $Dev = True
            GUICtrlSetData($Label1, "You are currently opperating in Developer Mode")
            GUICtrlSetState($RecipCombo, $GUI_DISABLE)
        ElseIf @error = 1 Then
            Sleep(10)
        Else
            MsgBox(0, "Failure", "Incorrect password", 10)
        EndIf
    Else
        MsgBox(0, "Dis-armed", "You have disabeled Developer Mode", 10)
        _Reset()
    EndIf
EndFunc   ;==>_DevMode

Func _SetCom()
    Local $SETRecip = GUICtrlRead($RecipCombo)
    GUICtrlSetData($mErrorCombo, "")
    If $SETRecip = "Material Issue" Then
        GUICtrlSetData($mErrorCombo, "WH Shortage|Wrong WH|Wrong LOT#|Ivalid LOT#|Invalid BIN|Incorrect Weight|Different Weight", "")
    ElseIf $SETRecip = "TimeKeep" Then
        GUICtrlSetData($mErrorCombo, "Wrong Time|Time not logged|Missed fields|", "")
    ElseIf $SETRecip = "IT Dept" Then
        GUICtrlSetData($mErrorCombo, "Keyboard/Mouse issues|Monitor issues|Computer Issues|Out of Ink|Printer not printing|Cable not working|Cable needs installed|Internet issues|Server issues|SYSPRO issues|ABC/BarCam issues|SET issues|Hand scanner issues|Other...", "")
    EndIf
EndFunc

Func _SendEmail()
    Local $SETIDcheck = GUICtrlRead($SETIDfield)
    Local $sTEST = StringRegExp($SETIDcheck, '\A0')
    If $sTEST=1 Then $SETIDcheck=StringTrimLeft($SETIDcheck, 1)
    Local $SETRecip = GUICtrlRead($RecipCombo)
    Local $Validate = 0
    If $Dev = True Then
            Local $MACa = StringReplace($IPDetails[1], ":", "")
            Local $Wstation = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "mac_addresses", $MACa, Default)
            Local $eCODE = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "system", "ecode", Default)
            Local $eID = IniRead($SYSTEMDRIVE & $eCODE, "eID_code", $SETIDcheck, Default)
            Local $SETcom = GUICtrlRead($mCmntBox)
            Local $SETres = GUICtrlRead($mErrorCombo)
            If $eID = "Default" Then $eID = $SETIDcheck
            If $Wstation = "Default" Then $Wstation = @ComputerName
            $SETComments = "Workstation: " & $Wstation & @CR & "Employee ID: " & $eID & @CRLF & "Reason code: " & $SETres & @CR & "ABC Data: " & $ABCData & @CR & "Comments:" & @CRLF & $SETcom
            GUIDelete("MainGUI")
            Sleep(10)
        _EmailResults()
    Else
        If $SETRecip = "Material Issue" Then
            $SETToAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "ToAddress_mi", Default)
            $Validate = $Validate + 1
        ElseIf $SETRecip = "TimeKeep" Then
            $SETToAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "ToAddress_tk", Default)
            $Validate = $Validate + 1
        ElseIf $SETRecip = "IT Dept" Then
            $SETToAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "ToAddress_it", Default)
            $Validate = $Validate + 1
        Else
            MsgBox(0, "Error", "You must select a recipient for the ticket")
        EndIf
        If $SETIDcheck = "" Or $SETIDcheck = 0 Or $SETIDcheck < 1 Then
            MsgBox(1, "Required Input", "You must enter your Employee ID to contiue" & @CRLF & "If you wish to exit this tool, press the ESCAPE key")
        Else
            $Validate = $Validate + 1
            Local $MACa = StringReplace($IPDetails[1], ":", "")
            Local $Wstation = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "mac_addresses", $MACa, Default)
            Local $eCODE = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "system", "ecode", Default)
            Local $eID = IniRead($eCODE, "eID_code", $SETIDcheck, Default)
            Local $SETcom = GUICtrlRead($mCmntBox)
            Local $SETres = GUICtrlRead($mErrorCombo)
            If $eID = "Default" Then $eID = $SETIDcheck
            If $Wstation = "Default" Then $Wstation = @ComputerName
            $SETComments = "Workstation: " & $Wstation & @CR & "Employee ID: " & $eID & @CRLF & "Reason code: " & $SETres & @CR & "ABC Data: " & $ABCData & @CR & "Comments:" & @CRLF & $SETcom

            GUIDelete("MainGUI")
            Sleep(10)
            If $Validate > 1 Then
                _EmailResults()
            Else
                MsgBox(0, "Error", "There are fields left incomplete, please be sure you have entered your employee number and the recipient of the ticket before submitting the ticket")
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_SendEmail

Func _ScreenGrab()
    FileDelete($SYSTEMDRIVE & "\SET\Screens\SET_SC.jpg")
    WinActivate("Program Manager")
    Send("{F5}")
    Sleep(10)
    Local $SEThBmp
    Sleep(10)
    ; Capture full screen
    $SEThBmp = _ScreenCapture_Capture("")
    Sleep(10)
    ; Save bitmap to file
    _ScreenCapture_SaveImage($SYSTEMDRIVE & "\SET\Screens\SET_SC.jpg", $SEThBmp)
    Sleep(2000)
EndFunc   ;==>_ScreenGrab

Func _EmailResults()
    $SETBody = $SETComments
    If $Dev = True Then $SETToAddress = IniRead($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "BccAddress", Default)
    $SETrc = _INetSmtpMailCom($SETSmtpServer, $SETFromName, $SETFromAddress, $SETToAddress, $SETSubject, $SETBody, $SETAttachFiles, $SETCcAddress, $SETBccAddress, $SETImportance, $SETUsername, $SETPassword, $SETIPPort, $SETssl)
    If @error Then
        MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $SETrc)
    Else
        _NotifySuccess()
    EndIf
    Exit
EndFunc   ;==>_EmailResults

Func _NotifySuccess()
    MsgBox(0, "Ticket Submitted", "The Error Tool successfuly submitted your ticket")
EndFunc   ;==>_NotifySuccess

;##################################
; Function that sends the email
;##################################
Func _INetSmtpMailCom($SETs_SmtpServer, $SETs_FromName, $SETs_FromAddress, $SETs_ToAddress, $SETs_Subject = "", $SETas_Body = "", $SETs_AttachFiles = "", $SETs_CcAddress = "", $SETs_BccAddress = "", $SETs_Importance = "Normal", $SETs_Username = "", $SETs_Password = "", $SETIPPort = 25, $SETssl = 0)
    Local $SETobjEmail = ObjCreate("CDO.Message")
    $SETobjEmail.From = '"' & $SETs_FromName & '" <' & $SETs_FromAddress & '>'
    $SETobjEmail.To = $SETs_ToAddress
    Local $SETi_Error = 0
    Local $SETi_Error_desciption = ""
    If $SETs_CcAddress <> "" Then $SETobjEmail.Cc = $SETs_CcAddress
    If $SETs_BccAddress <> "" Then $SETobjEmail.Bcc = $SETs_BccAddress
    $SETobjEmail.Subject = $SETs_Subject
    If StringInStr($SETas_Body, "<") And StringInStr($SETas_Body, ">") Then
        $SETobjEmail.HTMLBody = $SETas_Body
    Else
        $SETobjEmail.Textbody = $SETas_Body & @CRLF
    EndIf
    If $SETs_AttachFiles <> "" Then
        Local $SETS_Files2Attach = StringSplit($SETs_AttachFiles, ";")
        For $SETx = 1 To $SETS_Files2Attach[0]
            $SETS_Files2Attach[$SETx] = _PathFull($SETS_Files2Attach[$SETx])
;~          ConsoleWrite('@@ Debug : $SETS_Files2Attach[$SETx] = ' & $SETS_Files2Attach[$SETx] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($SETS_Files2Attach[$SETx]) Then
                ConsoleWrite('+> File attachment added: ' & $SETS_Files2Attach[$SETx] & @LF)
                $SETobjEmail.AddAttachment($SETS_Files2Attach[$SETx])
            Else
                ConsoleWrite('!> File not found to attach: ' & $SETS_Files2Attach[$SETx] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SETs_SmtpServer
    If Number($SETIPPort) = 0 Then $SETIPPort = 25
    $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $SETIPPort
    ;Authenticated SMTP
    If $SETs_Username <> "" Then
        $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $SETs_Username
        $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $SETs_Password
    EndIf
    If $SETssl Then
        $SETobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $SETobjEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $SETs_Importance
        Case "High"
            $SETobjEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $SETobjEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $SETobjEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $SETobjEmail.Fields.Update
    ; Sent the Message
    $SETobjEmail.Send
    If @error Then
        SetError(2)
        Return $SEToMyRet[1]
    EndIf
    $SETobjEmail = ""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $SETHexNumber = Hex($SEToMyError.number, 8)
    $SEToMyRet[0] = $SETHexNumber
    $SEToMyRet[1] = StringStripWS($SEToMyError.description, 3)
    FileWriteLine($SYSTEMDRIVE & "\SET\ErrorLogs\SET_error_log_" & @MON & "." & @MDAY & "." & @SEC & ".txt", "### COM Error !  Number: " & $SETHexNumber & "   ScriptLine: " & $SEToMyError.scriptline & "   Description:" & $SEToMyRet[1] & @LF & "END COM ERROR ####")
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

Func WM_NCHITTEST($SEThWnd, $SETiMsg, $SETwParam, $SETlParam);Window Dragging
    #forceref $SEThWnd, $SETiMsg, $SETwParam, $SETlParam
    Return $HTCAPTION
EndFunc   ;==>WM_NCHITTEST

Func MainGUIClose()
    GUIDelete("MainGUI")
    Exit
EndFunc   ;==>MainGUIClose

Func _vPrev()
    If $Preview == $SETAttachFiles Then
        ShellExecute($Preview)
    EndIf
EndFunc   ;==>_vPrev

Func _Reset();Exits, then runs the script again, thus resetting it
    If @Compiled Then
        Run(FileGetShortName(@ScriptFullPath))
    Else
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc   ;==>_Reset

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[5] = [4]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If $oObjectItem.IPAddress(0) == @IPAddress1 Then
                $aReturn[1] = $oObjectItem.MACAddress
                $aReturn[2] = $oObjectItem.DefaultIPGateway(0)
            EndIf
        Next
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _ABCReader()
        Local $ReadData1 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:7]")
        Local $ReadData2 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:4]")
        Local $ReadData3 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.STATIC.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:5]")
        Local $ReadData4 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:2]")
        Local $ReadData5 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.STATIC.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:4]")
        Local $ReadData6 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.STATIC.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:1]")
        Local $ReadData7 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:6]")
        Local $ReadData8 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:5]")
        Local $ReadData9 = ControlGetText("[REGEXPTITLE:Mat. Iss -  Version: 201[0-9].[0-9][0-9].[0-9][0-9].[0-9]]", "", "[REGEXPCLASS:WindowsForms10.EDIT.app.0.2bf8098_r1[0-9]_ad1; INSTANCE:1]")
    Sleep(100)

    $ABCData = $ReadData1 & @CR & $ReadData2 & @CR & $ReadData3 & @CR & $ReadData4 & @CR & $ReadData5 & @CR & $ReadData6 & @CR & $ReadData7 & @CR & $ReadData8 & @CR & $ReadData9
    If $ReadData9="" Then $ABCData="N/A"
EndFunc   ;==>_ABCReader

Func _WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    ; if it is our combo and it is closed after have been opened
    If BitAND($wParam, 0x0000FFFF) = $RecipCombo And BitShift($wParam, 16) = $CBN_CLOSEUP Then
        ; Fire the dummy
        GUICtrlSendToDummy($hDummy)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func _settings()
    If $Dev=True Then
        $settGUI = GUICreate("SETtings", 500, 232, 219, 133)
        $settGroup1 = GUICtrlCreateGroup(" Server IP ", 6, 8, 207, 63)
        Global $settInput1 = GUICtrlCreateInput($SETSmtpServer, 30, 34, 165, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $settGroup2 = GUICtrlCreateGroup(" From Address ", 222, 8, 273, 63, BitOR($GUI_SS_DEFAULT_GROUP,$BS_RIGHT))
        Global $settInput2 = GUICtrlCreateInput(StringTrimRight($SETFromAddress, 16), 242, 34, 115, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
        Global $settLabel3 = GUICtrlCreateLabel("@stormcopper.com", 370, 36)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $settGroup3 = GUICtrlCreateGroup(" User Credentials ", 6, 82, 489, 77, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
        Global $settInput3 = GUICtrlCreateInput($SETUsername, 90, 116, 145, 21)
        Global $settInput4 = GUICtrlCreateInput($SETPassword, 325, 116, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
        $settLabel1 = GUICtrlCreateLabel("Username", 16, 118)
        $settLabel2 = GUICtrlCreateLabel("Pass", 274, 118)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $settGroup4 = GUICtrlCreateGroup(" Port ", 6, 168, 205, 55)
        Global $settInput5 = GUICtrlCreateInput($SETIPPort, 74, 190, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $settButton1 = GUICtrlCreateButton("Apply", 238, 176, 117, 41)
        GUICtrlSetOnEvent(-1, "_sett_apply")
        $settButton2 = GUICtrlCreateButton("Cancel", 368, 176, 117, 41)
        GUICtrlSetOnEvent(-1, "_sett_cancel")
        GUISetState(@SW_SHOW, "SETtings")
    Else
        $credCheck = InputBox("Credentials Required", "To change settings enter the required credentials", "", "*")


        If $credCheck = $KEY Then
            $settGUI = GUICreate("SETtings", 500, 232, 219, 133)
            $settGroup1 = GUICtrlCreateGroup(" Server IP ", 6, 8, 207, 63)
            Global $settInput1 = GUICtrlCreateInput($SETSmtpServer, 28, 34, 165, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            $settGroup2 = GUICtrlCreateGroup(" From Address ", 222, 8, 273, 63, BitOR($GUI_SS_DEFAULT_GROUP,$BS_RIGHT))
            Global $settInput2 = GUICtrlCreateInput(StringTrimRight($SETFromAddress, 16), 242, 34, 115, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_RIGHT))
            Global $settLabel3 = GUICtrlCreateLabel("@stormcopper.com", 370, 36)
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            $settGroup3 = GUICtrlCreateGroup(" User Credentials ", 6, 82, 489, 77, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
            Global $settInput3 = GUICtrlCreateInput($SETUsername, 90, 116, 145, 21)
            Global $settInput4 = GUICtrlCreateInput($SETPassword, 325, 116, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
            $settLabel1 = GUICtrlCreateLabel("Username", 16, 118)
            $settLabel2 = GUICtrlCreateLabel("Pass", 274, 118)
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            $settGroup4 = GUICtrlCreateGroup(" Port ", 6, 168, 205, 55)
            Global $settInput5 = GUICtrlCreateInput($SETIPPort, 74, 190, 65, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            $settButton1 = GUICtrlCreateButton("Apply", 238, 176, 117, 41)
            GUICtrlSetOnEvent(-1, "_sett_apply")
            $settButton2 = GUICtrlCreateButton("Cancel", 368, 176, 117, 41)
            GUICtrlSetOnEvent(-1, "_sett_cancel")
            GUISetState(@SW_SHOW, "SETtings")
        ElseIf @error = 1 Then
            Sleep(10)
        Else
            MsgBox(0, "Failure", "Incorrect password", 10)
        EndIf
    EndIf
EndFunc

Func _sett_apply()
    Local $server=GUICtrlRead($settInput1)
    Local $FromAdd1=GUICtrlRead($settInput2)
    Local $FromAdd2=$FromAdd1 & "@stormcopper.com"
    Local $Username=GUICtrlRead($settInput3)
    Local $pass=GUICtrlRead($settInput4)
    Local $port=Number(GUICtrlRead($settInput5))
    Local $error=0

    IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "FromAddress", $FromAdd2)
    If @error Then Local $error=1
    IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "SmtpServer", $server)
    If @error Then Local $error=2
    IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Username", $Username)
    If @error Then Local $error=3
    IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "Password", $pass)
    If @error Then Local $error=4
    IniWrite($SYSTEMDRIVE & "\SET\Ctrl.ini", "emailinfo", "IPPort", $port)
    If @error Then Local $error=5

    If $error=0 Then
        MsgBox(0, "Success", "Settings successfully applied!", 5)
    ElseIf $error=1 Then
        MsgBox(0, "Failure", "Settings failed to applied, unable to apply FromAddress value", 10)
    ElseIf $error=2 Then
        MsgBox(0, "Failure", "Settings failed to applied, unable to apply Server IP value", 10)
    ElseIf $error=3 Then
        MsgBox(0, "Failure", "Settings failed to applied, unable to apply Username value", 10)
    ElseIf $error=4 Then
        MsgBox(0, "Failure", "Settings failed to applied, unable to apply Pass value", 10)
    ElseIf $error=5 Then
        MsgBox(0, "Failure", "Settings failed to applied, unable to apply Port value", 10)
    EndIf
    Sleep(100)
    GUIDelete("SETtings")
EndFunc

Func _sett_cancel()
    GUIDelete("SETtings")
EndFunc

Func _RD_show()


GUISetState(@SW_HIDE, "Storm Error Tool")
Sleep(100)
$rdGUI = GUICreate("Research and Development", 408, 569, 765, 188)
GUISetOnEvent($GUI_EVENT_CLOSE, "_rdGUIClose")
$RD_Group1 = GUICtrlCreateGroup(" Storm Research and Development Job Tracking ", 4, 4, 399, 561, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
$RD_Group2 = GUICtrlCreateGroup(" Job control ", 12, 422, 381, 135)
Global $RD_Button1 = GUICtrlCreateButton("Start", 20, 518, 81, 33)
GUICtrlSetOnEvent(-1, "_Start_Job")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $RD_Button2 = GUICtrlCreateButton("End", 304, 518, 81, 33)
GUICtrlSetOnEvent(-1, "_End_Job")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $RD_Timer = GUICtrlCreateInput("00:00:00", 308, 434, 78, 20, BitOR($ES_CENTER, $ES_READONLY))
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetFont(-1, 10, 700)
GUICtrlSetBkColor(-1, 0xFF0000)
$RD_Label1 = GUICtrlCreateLabel("Current Job", 174, 436, 58, 17)
Global $RD_ListView1 = GUICtrlCreateListView("", 20, 460, 365, 50, $LVS_NOSCROLL)
Global $RD_LV_Handle = GUICtrlGetHandle($RD_ListView1)
_GUICtrlListView_SetExtendedListViewStyle($RD_LV_Handle, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_AddColumn($RD_LV_Handle, "Sales Order", 100)
_GUICtrlListView_AddColumn($RD_LV_Handle, "Part Number", 125)
_GUICtrlListView_AddColumn($RD_LV_Handle, "EiD", 50)
_GUICtrlListView_AddColumn($RD_LV_Handle, "Workcenter", 100)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $RD_Input1 = GUICtrlCreateInput("", 98, 74, 213, 21)
Global $RD_Input2 = GUICtrlCreateInput("", 98, 136, 213, 21)
Global $RD_Input3 = GUICtrlCreateInput("", 96, 196, 213, 21, $GUI_SS_DEFAULT_INPUT)
Global $RD_Combo1 = GUICtrlCreateCombo("", 96, 258, 213, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Trumpf2000|Trumpf500|HAAS-LATHE|Tsugami|HAAS-CNC|Brake|BBM|WaterJet|CP750|Euromac|Powdercoat", "")
$RD_Label2 = GUICtrlCreateLabel("Sales Order", 165, 46)
$RD_Label3 = GUICtrlCreateLabel("Part Number", 165, 108)
$RD_Label4 = GUICtrlCreateLabel("Employee ID", 165, 170)
$RD_Label5 = GUICtrlCreateLabel("Workcenter", 165, 232)
Global $RD_Button3 = GUICtrlCreateButton("Create Tracker", 96, 324, 213, 61)
GUICtrlSetOnEvent(-1, "_CreateTracker")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW, "Research and Development")
EndFunc

Func _rdGUIClose()
    GUIDelete("Research and Development")
    Sleep(100)
    GUISetState(@SW_SHOW, "Storm Error Tool")
EndFunc

Func _CreateTracker()
    Global $JOB[4] = [GUICtrlRead($RD_Input1), GUICtrlRead($RD_Input2), GUICtrlRead($RD_Input3), GUICtrlRead($RD_Combo1)]
    Local $data=_ArrayToString($JOB)
    $SQL_data=StringReplace($data, "|", "', '")

    If GUICtrlRead($RD_Input1)<> "" And GUICtrlRead($RD_Input2)<> "" And GUICtrlRead($RD_Input3)<> "" And GUICtrlRead($RD_Combo1)<> "" And GUICtrlGetState($RD_Button1) = 144  Then
        GUICtrlSetData($RD_Input1, "")
        GUICtrlSetData($RD_Input2, "")
        GUICtrlSetData($RD_Input3, "")
        GUICtrlSetData($RD_Combo1, "")
        GUICtrlSetData($RD_Combo1, "Trumpf2000|Trumpf500|HAAS-LATHE|Tsugami|HAAS-CNC|Brake|BBM|WaterJet|CP750|Euromac|Powdercoat", "")
        _GUICtrlListView_AddItem($RD_LV_Handle, $JOB[0])
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[1], 1, 1)
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[2], 2, 2)
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[3], 3, 3)
        GUICtrlSetState($RD_Button3, $GUI_DISABLE)
        GUICtrlSetState($RD_Button1, $GUI_ENABLE)
    Else
        MsgBox(48, "! Attention !", "You must fill out all fields available including the workcenter before creating a tracking job.", 5)
    EndIf
EndFunc

Func _Start_Job()
    $timer = TimerInit()
    GUICtrlSetBkColor($RD_Timer, 0x00b805)
    AdlibRegister("_timer", 50)
    GUICtrlSetState($RD_Button1, $GUI_DISABLE)
    GUICtrlSetState($RD_Button2, $GUI_ENABLE)
EndFunc

Func _timer()
    _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
    Local $sTime = $Time ; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    If $sTime <> $Time Then GUICtrlSetData($RD_Timer, $Time)
EndFunc

Func _End_Job()
    GUICtrlSetBkColor($RD_Timer, 0xFF0000)
    AdlibUnRegister("_timer")
    GUICtrlSetState($RD_Button2, $GUI_DISABLE)
    $t=GUICtrlRead($RD_Timer)
    GUIDelete("Research and Development")
    _SQL()
    If @error Then MsgBox(0, "ERROR", @error)
    Sleep(1000)
    _RD_show()
EndFunc

Func _SQL()
    Local $Comma=Chr(44)
    Local $cQ=Chr(39)
    Local $oPara=Chr(40)
    Local $cPara=Chr(41)
    Local $ServerAddress = "myIP"
    Local $ServerUserName = "myUID"
    Local $ServerPassword = "myPWD"
    Local $DatabaseName = "myDBO"

    _SQL_RegisterErrorHandler();register the error handler to prevent hard crash on COM error

    $OADODB = _SQL_Startup()

    If $OADODB = $SQL_ERROR Then MsgBox(0 + 16 + 262144, "Error", _SQL_GetErrMsg())
    If _sql_Connect($OADODB, $ServerAddress, $DatabaseName, $ServerUserName, $ServerPassword) = $SQL_ERROR Then
    MsgBox(0 + 16 + 262144, "Error 1", _SQL_GetErrMsg())
    _SQL_Close()
    Exit
    EndIf

    Local $fullSQL
;~  Local $test="insert into tbl_ResearchDev" & $oPara & "SalesOrder" & $Comma & " StockCode" & $Comma & " EmpID" & $Comma & " WorkCentre" & $Comma & " JobTime" & $cPara & " Values " & $oPara & $cQ & $SQL_data & $cQ & ", '" & $t & "'" & $cPara
;~  MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$test' & @CRLF & @CRLF & 'Return:' & @CRLF & $test) ;### Debug MSGBOX

Local $test="test"
Local $123="123"


If _Sql_Execute($OADODB, "insert into tbl_ResearchDev(SalesOrder, StockCode, EmpID, WorkCentre, JobTime) Values('" & $test & "', '" & $test & "', '" & $test & "', '" & $test & "', '" & $123 & "')") = $SQL_OK Then
Else
    MsgBox(0 + 16 + 262144, "SQL Error", _SQL_GetErrMsg())
EndIf
EndFunc

The section regarding the SQL functions are here:

Func _RD_show()


GUISetState(@SW_HIDE, "Storm Error Tool")
Sleep(100)
$rdGUI = GUICreate("Research and Development", 408, 569, 765, 188)
GUISetOnEvent($GUI_EVENT_CLOSE, "_rdGUIClose")
$RD_Group1 = GUICtrlCreateGroup(" Storm Research and Development Job Tracking ", 4, 4, 399, 561, BitOR($GUI_SS_DEFAULT_GROUP,$BS_CENTER))
$RD_Group2 = GUICtrlCreateGroup(" Job control ", 12, 422, 381, 135)
Global $RD_Button1 = GUICtrlCreateButton("Start", 20, 518, 81, 33)
GUICtrlSetOnEvent(-1, "_Start_Job")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $RD_Button2 = GUICtrlCreateButton("End", 304, 518, 81, 33)
GUICtrlSetOnEvent(-1, "_End_Job")
GUICtrlSetState(-1, $GUI_DISABLE)
Global $RD_Timer = GUICtrlCreateInput("00:00:00", 308, 434, 78, 20, BitOR($ES_CENTER, $ES_READONLY))
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetFont(-1, 10, 700)
GUICtrlSetBkColor(-1, 0xFF0000)
$RD_Label1 = GUICtrlCreateLabel("Current Job", 174, 436, 58, 17)
Global $RD_ListView1 = GUICtrlCreateListView("", 20, 460, 365, 50, $LVS_NOSCROLL)
Global $RD_LV_Handle = GUICtrlGetHandle($RD_ListView1)
_GUICtrlListView_SetExtendedListViewStyle($RD_LV_Handle, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
_GUICtrlListView_AddColumn($RD_LV_Handle, "Sales Order", 100)
_GUICtrlListView_AddColumn($RD_LV_Handle, "Part Number", 125)
_GUICtrlListView_AddColumn($RD_LV_Handle, "EiD", 50)
_GUICtrlListView_AddColumn($RD_LV_Handle, "Workcenter", 100)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $RD_Input1 = GUICtrlCreateInput("", 98, 74, 213, 21)
Global $RD_Input2 = GUICtrlCreateInput("", 98, 136, 213, 21)
Global $RD_Input3 = GUICtrlCreateInput("", 96, 196, 213, 21, $GUI_SS_DEFAULT_INPUT)
Global $RD_Combo1 = GUICtrlCreateCombo("", 96, 258, 213, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Trumpf2000|Trumpf500|HAAS-LATHE|Tsugami|HAAS-CNC|Brake|BBM|WaterJet|CP750|Euromac|Powdercoat", "")
$RD_Label2 = GUICtrlCreateLabel("Sales Order", 165, 46)
$RD_Label3 = GUICtrlCreateLabel("Part Number", 165, 108)
$RD_Label4 = GUICtrlCreateLabel("Employee ID", 165, 170)
$RD_Label5 = GUICtrlCreateLabel("Workcenter", 165, 232)
Global $RD_Button3 = GUICtrlCreateButton("Create Tracker", 96, 324, 213, 61)
GUICtrlSetOnEvent(-1, "_CreateTracker")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW, "Research and Development")
EndFunc

Func _rdGUIClose()
    GUIDelete("Research and Development")
    Sleep(100)
    GUISetState(@SW_SHOW, "Storm Error Tool")
EndFunc

Func _CreateTracker()
    Global $JOB[4] = [GUICtrlRead($RD_Input1), GUICtrlRead($RD_Input2), GUICtrlRead($RD_Input3), GUICtrlRead($RD_Combo1)]
    Local $data=_ArrayToString($JOB)
    $SQL_data=StringReplace($data, "|", "', '")

    If GUICtrlRead($RD_Input1)<> "" And GUICtrlRead($RD_Input2)<> "" And GUICtrlRead($RD_Input3)<> "" And GUICtrlRead($RD_Combo1)<> "" And GUICtrlGetState($RD_Button1) = 144  Then
        GUICtrlSetData($RD_Input1, "")
        GUICtrlSetData($RD_Input2, "")
        GUICtrlSetData($RD_Input3, "")
        GUICtrlSetData($RD_Combo1, "")
        GUICtrlSetData($RD_Combo1, "Trumpf2000|Trumpf500|HAAS-LATHE|Tsugami|HAAS-CNC|Brake|BBM|WaterJet|CP750|Euromac|Powdercoat", "")
        _GUICtrlListView_AddItem($RD_LV_Handle, $JOB[0])
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[1], 1, 1)
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[2], 2, 2)
        _GUICtrlListView_AddSubItem($RD_ListView1, 0, $JOB[3], 3, 3)
        GUICtrlSetState($RD_Button3, $GUI_DISABLE)
        GUICtrlSetState($RD_Button1, $GUI_ENABLE)
    Else
        MsgBox(48, "! Attention !", "You must fill out all fields available including the workcenter before creating a tracking job.", 5)
    EndIf
EndFunc

Func _Start_Job()
    $timer = TimerInit()
    GUICtrlSetBkColor($RD_Timer, 0x00b805)
    AdlibRegister("_timer", 50)
    GUICtrlSetState($RD_Button1, $GUI_DISABLE)
    GUICtrlSetState($RD_Button2, $GUI_ENABLE)
EndFunc

Func _timer()
    _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
    Local $sTime = $Time ; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    If $sTime <> $Time Then GUICtrlSetData($RD_Timer, $Time)
EndFunc

Func _End_Job()
    GUICtrlSetBkColor($RD_Timer, 0xFF0000)
    AdlibUnRegister("_timer")
    GUICtrlSetState($RD_Button2, $GUI_DISABLE)
    $t=GUICtrlRead($RD_Timer)
    GUIDelete("Research and Development")
    _SQL()
    If @error Then MsgBox(0, "ERROR", @error)
    Sleep(1000)
    _RD_show()
EndFunc

Func _SQL()
    Local $Comma=Chr(44)
    Local $cQ=Chr(39)
    Local $oPara=Chr(40)
    Local $cPara=Chr(41)
    Local $ServerAddress = "10.0.0.25"
    Local $ServerUserName = "sa2"
    Local $ServerPassword = "storm2009"
    Local $DatabaseName = "BarcodeTest"

    _SQL_RegisterErrorHandler();register the error handler to prevent hard crash on COM error

    $OADODB = _SQL_Startup()

    If $OADODB = $SQL_ERROR Then MsgBox(0 + 16 + 262144, "Error", _SQL_GetErrMsg())
    If _sql_Connect($OADODB, $ServerAddress, $DatabaseName, $ServerUserName, $ServerPassword) = $SQL_ERROR Then
    MsgBox(0 + 16 + 262144, "Error 1", _SQL_GetErrMsg())
    _SQL_Close()
    Exit
    EndIf

    Local $fullSQL
;~  Local $test="insert into tbl_ResearchDev" & $oPara & "SalesOrder" & $Comma & " StockCode" & $Comma & " EmpID" & $Comma & " WorkCentre" & $Comma & " JobTime" & $cPara & " Values " & $oPara & $cQ & $SQL_data & $cQ & ", '" & $t & "'" & $cPara
;~  MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & '$test' & @CRLF & @CRLF & 'Return:' & @CRLF & $test) ;### Debug MSGBOX

Local $test="test"
Local $123="123"


If _Sql_Execute($OADODB, "insert into tbl_ResearchDev(SalesOrder, StockCode, EmpID, WorkCentre, JobTime) Values('" & $test & "', '" & $test & "', '" & $test & "', '" & $test & "', '" & $123 & "')") = $SQL_OK Then
Else
    MsgBox(0 + 16 + 262144, "SQL Error", _SQL_GetErrMsg())
EndIf
EndFunc

apparently I'm unable to wrap my mind around it...


Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Share this post


Link to post
Share on other sites
Wombat

I found a simple solution which was reading each seperate item into it's own variable... Thread closed.


Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×