skybax Posted July 29, 2013 Posted July 29, 2013 Hello everyone, i have a problem, im using an array to read some data from mysql and i want to check if that array is not null $SQLCode_raport_tip2 = "SELECT `Sala` , SUM(cantitate) FROM `raspandire` WHERE `data` BETWEEN '"&GUICtrlRead($data_de_la)&"' AND '"&GUICtrlRead($data_pana_la)&"'AND `Tip`=2 GROUP BY `Sala`" $TableContents_tip2 = _Query($SQLInstance,$SQLCode_raport_tip2) Global $bResult[10001][4] = [[10000, 4]] Global $iIndex2 With $TableContents_tip2 While Not .EOF $bResult[$iIndex2][0] = "Selector" $bResult[$iIndex2][1] = .Fields("Sala").value $bResult[$iIndex2][2] = .Fields("SUM(cantitate)").value $bResult[$iIndex2][3] = GUICtrlRead($curs_valutar)*251 $iIndex2 = $iIndex2 + 1 .MoveNext WEnd EndWith ReDim $bResult[$iIndex2][4] If i run this code and it finds some inputs in mysql everything is ok, but if MySQL returned an empty result it crashes my program SELECT `Sala` , SUM( cantitate ) FROM `raspandire` WHERE `data` BETWEEN '2013-07-29' AND '2013-07-29' AND `Tip` =2 GROUP BY `Sala` Array variable subscript badly formatted.: ReDim $bResult[$iIndex2][4] ReDim $bResult[^ ERROR What can i do to make it skip ReDim $bResult[$iIndex2][4] if the result is null? i have tried something like this but with no succes it crashes or it enters a loop and freezes the program If $bResult <> "" Then MsgBox(-1,"TEST"," EMPTY") Else ReDim $bResult[$iIndex2][4] EndIf
Artisan Posted July 29, 2013 Posted July 29, 2013 (edited) Looks like you've got your code backwards. Try something like this: If $bResult = "" Then MsgBox(-1,"TEST"," EMPTY") Else ReDim $bResult[$iIndex2][4] EndIf Or even: If $bResult <> "" Then ReDim $bResult[$iIndex2][4] EndIf Edited July 29, 2013 by Artisan
michaelslamet Posted July 29, 2013 Posted July 29, 2013 Hi, You may want to take a time to see this function: IsArray()
skybax Posted July 29, 2013 Author Posted July 29, 2013 (edited) This dosent work i get Array variable subscript badly formatted.: If $bResult = "" Then MsgBox(-1,"TEST"," EMPTY") Else ReDim $bResult[$iIndex2][4] EndIf Same thing here If $bResult <> "" Then ReDim $bResult[$iIndex2][4] EndIf Edited July 29, 2013 by skybax
Solution skybax Posted July 30, 2013 Author Solution Posted July 30, 2013 (edited) Hi, You may want to take a time to see this function: IsArray() I have tried IsArray but with n success. If IsArray($bResult) Then ReDim $bResult[$iIndex2][4] EndIf I still get this when i get a null result from mysql ReDim $aResult[$iIndex][4] ReDim $aResult[^ ERROR LE: I managed to solve this by adding the condition to the $iIndex If $iIndex2 > 0 then ReDim $bResult[$iIndex2][4] EndIf Edited July 30, 2013 by skybax
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