Jump to content
Queener

Subscript used on non-accessible variable

Recommended Posts

Queener

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.")

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Queener

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 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.")

Share this post


Link to post
Share on other sites
MikahS

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()
EndIf

Check 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 ~ getENVvars
My 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

 

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Queener

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 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.")

Share this post


Link to post
Share on other sites
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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

×