Sign in to follow this  
Followers 0
IvanCodin

Display error

3 posts in this topic

#1 ·  Posted (edited)

I have a script that uses a UDF to query a database. When I run the script if there is a match for ther query it runs successfully. if there is not match for the query i get an error. I add a entry to the UDF to trap the error.

Code from the script is here:

CODE
#include <GUIConstants.au3>

#include "_DBlistView.au3"

#include <array.au3>

Do

$strName = InputBox("Input","Enter all or part of a company name to search for:",""," M")

Until StringRegExp($strName,"^[a-zA-z0-9]+$")

MsgBox(0,"Info", "You entered " & $strname, 8)

Opt("GUIOnEventMode", 1); OnEvent mode

Dim $title="Access db Viewer";gui title

Dim $gui = GUICreate($title, 600, 600)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

$DB = @ScriptDir & "\test.mdb"

$Query= "SELECT CompanyName,CompanyAddress1,CompanyCity,CompanyState FROM CompanyName WHERE CompanyName LIKE " & "'" & $strName & "%' " & "ORDER BY CompanyName Asc"

; MsgBox(0,"Info", $Query, 8)

$Number_of_Records_to_Display = 20

$Listview_Left = 100

$Listview_Top = 50

$Listview_Width = 600

$Listview_Height = 400

$Listview_style = $GUI_SS_DEFAULT_LISTVIEW;default is -1

$Listview_exStyle = $LVS_EX_FULLROWSELECT + $LVS_EX_GRIDLINES;default is -1

$dblv = _createDBlistView($DB,$Query,$Number_of_Records_to_Display,$Listview_Left,$Listview_Top,$Listview_Width,$Listview_Height,$Listview_style,$Listview_exStyle)

$ed1 = GUICtrlCreateEdit('',$Listview_Left,$Listview_Top + $Listview_Height,$Listview_Width,100)

GUISetState ()

$selected = -1

$lastselected = -1

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

While 1

Sleep(100); Idle around

WEnd

#cs @@@@@@@@@@@@@@@@@@@

$InputString = "CompanyName|CompanyAddress1|CompanyCity|CompanyState" ; simulated result of the dblclick event.

Local $text = $InputString

; Local $aArray = StringSplit ( $String, '|' )

$ArrayinArray = StringSplit($text,'|')

_ArrayDisplay ( $text )

$CompanyName = $ArrayInArray[1]

$CompanyAddress1 = $ArrayInArray[2]

$CompanyCity = $ArrayInArray[3]

$CompanyState = $ArrayInArray[4]

MsgBox( 0,"My Info", "I now have " & $CompanyName & $CompanyAddress1 & @CR & @LF & $CompanyCity & $CompanyState & " to set as variables", 8)

#ce @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Local $text ,$ItText

$text = GUICtrlRead($ed1);read the text in the edit

$ItText = _GUICtrlListView_GetItemTextString($dblv,-1);read the items in the row double clicked

;Item text could be spilt into its parts using stringsplit

$text &= $ItText;add the items string to the text

GUICtrlSetData($ed1,$text & @CRLF);write the text into the edit;

;EndFunc ;==>Button_Click

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)

#forceref $hWndGUI, $MsgID, $wParam

Local $tagNMHDR, $event

$tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)

If @error Then Return

$event = DllStructGetData($tagNMHDR, 3)

Select

Case $wParam = $dblv

Select

Case $event = $NM_CLICK ;ListView_Click();func could be written to handle this

Case $event = $NM_DBLCLK

ListView_DoubleClick()

EndSelect

EndSelect

$tagNMHDR = 0

$event = 0

$lParam = 0

EndFunc ;

Func CLOSEClicked()

Exit

EndFunc

The error points to line 130 in the _dblistview.au3 UDF.

I placed a error handler after the returned rows failure in an attemp to resolve the no vaild returned data result.

Code from UDF where error is located here:

CODE
Func dbselect($query)

MsgBox(0, "ts", "dbselect line 109", 4)

DB_Open()

$rs = ObjCreate("ADODB.recordset")

$rs.Open ($query, $conn)

$tableField_Names=""

For $tablefield in $rs.fields

$tableField_Names &= $tablefield.name & "|"

next

$getRows_Data=$rs.GetRows()

if @error then ; <----- These are the lines I attempted to capture the error.

Msgbox(0,"Error", "No records exist with this string.", 8) ; <----- These are the lines I attempted to capture the error.

exit ; <----- These are the lines I attempted to capture the error.

endif ; <----- These are the lines I attempted to capture the error.

$rs.close

DB_Close()

return $getRows_Data ;=>_createDBlistView()

EndFunc

Thanks

CC

Edited by IvanCodin

Share this post


Link to post
Share on other sites



I suppose the $getRows_Data is supposed to be an array.Just add 'Or Not IsArray($getRows_data)' to the @error line and try again.

Share this post


Link to post
Share on other sites

Is this what you are referring to:

$getRows_Data=$rs.GetRows()

if @error 'Or Not IsArray($getRows_data)' then

Msgbox(0,"Error", "No records exist with this string.", 8)

exit

endif

CC

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  
Followers 0