Queener Posted May 12, 2015 Share Posted May 12, 2015 Everytime when the record could not be found in database, I get a crash:Subscript used on non-accessible variable The error is pointing at $a1row[0]. If Not _EzMYSql_Query("SELECT InvenID FROM Inventory WHERE AssetTag like '%" & GUICtrlRead($InputAsset) & "%'" ) Then MsgBox(0, "Query Error", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Return EndIf $a1Row = _EzMySql_FetchData() GUICtrlSetData($MIDLabel, $a1Row[0]) Can someone help with this? Much appreicated. Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") Link to comment Share on other sites More sharing options...
water Posted May 12, 2015 Share Posted May 12, 2015 Seems that _EzMySql_FetchData doesn't return any values and hence $a1Row is not an array.Do some error checking after _EzMySql_FetchData. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Queener Posted May 12, 2015 Author Share Posted May 12, 2015 (edited) well the purpose is if it doesn't find any assettag then it prompt me a msg saying it does not exist. Thats where I'm going... I'm thinking about something like this unless you have a better idea? If Not _EzMYSql_Query("select exists(select * from inventory where assetTag like '%" & GUICtrlRead($InputAsset) & "%')") Then MsgBox(0, "Query Error", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) Return EndIf $a1Row = _EzMySql_FetchData()If $a1Row[0] = 1 Then MsgBox(0, "Exist", "This AssetTag existed in the database. You cannot add it as new.") Else Search() EndIf And I do not know how to do an error check on $a1Row[0]. Edited May 12, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") Link to comment Share on other sites More sharing options...
MikahS Posted May 12, 2015 Share Posted May 12, 2015 instead of this:If $a1Row[0] = 1 Then MsgBox(0, "Exist", "This AssetTag existed in the database. You cannot add it as new.") Else Search() EndIfCheck if it is actually an array:If IsArray($a1Row) Then MsgBox(0, "Exist", "This AssetTag existed in the database. You cannot add it as new.") Else Search() EndIf Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
water Posted May 12, 2015 Share Posted May 12, 2015 Check that _EzMySQL_FetchData really creates the array:$a1Row = _EzMySql_FetchData() If not IsArray($a1Row) Then Exit MsgBox(0, "Error", "_EzMySql_FetchData returned an error!")or something similar. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Queener Posted May 12, 2015 Author Share Posted May 12, 2015 (edited) when I run that code; I did not get an error... Rather it's in database or not I did not get that error. Though, If $a1Row[0] = 1 Then MsgBox(0, "Exist", "This AssetTag existed in the database. You cannot add it as new.") Else MsgBox(0, "Does not Exist", "This AssetTag does not existed in the database. You can add it as new.") EndIf Did worked like I mention, but was hoping if I can short it with other method... Edited May 12, 2015 by asianqueen Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.") Link to comment Share on other sites More sharing options...
water Posted May 12, 2015 Share Posted May 12, 2015 You can't check $a1row[0] = 1 because when there is an error (means: _EzMySql_FetchData does not return any data) then $a1row is not an array and you will see error "Subscript used on non-accessible variable". So you need to check if _EzMySql_FetchData ran successfully. Either by checking for an error (don't know how _EzMySql_FetchData does return an error - you need to check the docu) or by checking $a1row to be an array as suggested above. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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