AGsol Posted November 26, 2010 Share Posted November 26, 2010 Hi All Second time in a couple of days, think I might be getting lazy. I have created a GUI front end to an SQL Database everything is working fine and I'm happy with Version 1. What I would like to add is some custom quick searchs to my GUI this works fine if something exists but if no data is found the GUI is closed and the below output is displayed. I was wondering if anyone knows how I can put some error checking in place to prevent this crash. The requested action with this object has failed.: $Txt = $Txt & $query.GetString(2, -1, @TAB, @CR, "Null") $Txt = $Txt & $query.GetString(2, -1, @TAB, @CR, "Null")^ ERROR Below example script should be enough to show what I'm doing expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstants.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <Array.au3> #include <WindowsConstants.au3> Local $ExportGui, $FindGui, $FileExport, $Hostname, $Model, $Site, $ScrappedBy, $aInfo Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Opt("GUIOnEventMode", 1) $Main = GUICreate("SQL Reporter", 800, 275, 193, 115) $Menu = GuiCtrlCreateMenu("File") $exititem = GUICtrlCreateMenuitem ("Exit",$Menu) GUICtrlSetOnEvent(-1, "Cancel") $Menu2 = GuiCtrlCreateMenu("View") $Refreshitem = GUICtrlCreateMenuitem ("Refresh List",$Menu2) GUICtrlSetOnEvent(-1, "Refresh") GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $ListView1 = GUICtrlCreateListView("Name1|Name2|Name3|Name4|Name5", 30, 5, 740, 200, -1, $iExWindowStyle) GUICtrlSetOnEvent($ListView1, "columnscript") $ExportSQL = GUICtrlCreateButton("&Scrap", 30, 220, 60, 30, 0) GUICtrlSetOnEvent(-1, "Add") $AddSQL = GUICtrlCreateButton("&Find", 90, 220, 60, 30, 0) GUICtrlSetOnEvent(-1, "Find") $DeleteSQL = GUICtrlCreateButton("&Export", 150, 220, 60, 30, 0) GUICtrlSetOnEvent(-1, "Export") $conn = ObjCreate("ADODB.Connection") $conn.Properties("Prompt") = 2; 1=PromptAlways, 2=PromptComplete $ConString = "DRIVER={SQL Server};SERVER=SERVERNAME;DATABASE=DATABASENAME;UID=autoit;PWD=autoit;" $conn.Open($ConString) $query = ObjCreate("ADODB.RecordSet") $query.Open("USE Autoit SELECT DISTINCT Name1, Name2, Name3, Name4, Name5 WHERE NOT Name1 = '0' GROUP BY Name1", $conn) $Txt = "" $Txt = $Txt & $query.GetString(2, -1, @TAB, @CR, "Null") ;issue is here because no data is sent to the getstring $Display2 = StringSplit($Txt, @CRLF) For $x = 1 to $Display2[0] If $Display2[$x] = "" Then Else $Display = StringSplit($Display2[$x], @TAB) $ListView1_0 = GUICtrlCreateListViewItem($Display[1] & "|" & $Display[2] & "|" & $Display[3] & "|" & $Display[4] & "|" & $Display[5], $ListView1) EndIf Next $conn.close GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func Cancel() Exit EndFunc Func Add() EndFunc Func Find() EndFunc Func Find2() EndFunc Func FindCancel() EndFunc Func Export() EndFunc Func Export2() EndFunc Func ExportCancel() EndFunc Func Browse() EndFunc Func Delete() EndFunc Func Refresh() EndFunc Func columnscript() EndFunc Func SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE Exit Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE Case @GUI_CTRLID = $GUI_EVENT_RESTORE EndSelect EndFunc Regards, Ian Link to comment Share on other sites More sharing options...
ChrisL Posted November 26, 2010 Share Posted November 26, 2010 Either get the count before trying to get the strings, write an AutoIt COM Error handler or use some or all of my which has a COM error handler in it [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
AGsol Posted November 29, 2010 Author Share Posted November 29, 2010 Either get the count before trying to get the strings, write an AutoIt COM Error handler or use some or all of my which has a COM error handler in itThanks Chris your Error Handler did the trick, great work. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now