FrancescoDiMuro Posted September 15, 2017 Share Posted September 15, 2017 (edited) Good morning everyone I'm working on a little project, and, I encountered a little strange error when I try to add some data to an array... The code I wrote is this: expandcollapse popupFunc _WMI_Get_Win32_TemperatureProbe($blnCanUseWMI, $blnCustomArrayDisplay = False, $blnReturnEU = False) If $blnCanUseWMI Then Local $objWMI_QueryResult = $objWMI.ExecQuery("SELECT * FROM Win32_TemperatureProbe", "WQL", 32) If @error Then __ConsoleWrite("Error executing the query on Win32_TemperatureProbe class.", @error, 9999) Else Local $arrWin32_TemperatureProbe[1][3] _ArrayDelete($arrWin32_TemperatureProbe, 0) If @error Then __ConsoleWrite("Error deleting the 0st element $arrWin32_TemperatureProbe array.", @error, 9999) Else Local $objWMI_Variable = Null, $strWMI_QueryResult = "", $i = 0 For $objWMI_Variable In $objWMI_QueryResult $strWMI_QueryResult &= "QUERY RESULT" & "|# " & $i & "|/" & @CRLF & _ "Accuracy" & "|" & $objWMI_Variable.Accuracy & "|" & "[sint32]" & @CRLF & _ "Availability" & "|" & $objWMI_Variable.Availability & "|" & "[uint16]" & @CRLF & _ "Caption" & "|" & $objWMI_Variable.Caption & "|" & "[string]" & @CRLF & _ "ConfigManagerErrorCode" & "|" & $objWMI_Variable.ConfigManagerErrorCode & "|" & "[uint32]" & @CRLF & _ "ConfigManagerUserConfig" & "|" & $objWMI_Variable.ConfigManagerUserConfig & "|" & "[boolean]" & @CRLF & _ "CreationClassName" & "|" & $objWMI_Variable.CreationClassName & "|" & "[string]" & @CRLF & _ "CurrentReading" & "|" & $objWMI_Variable.CurrentReading & "|" & "[sint32]" & @CRLF & _ "Description" & "|" & $objWMI_Variable.Description & "|" & "[string]" & @CRLF & _ "DeviceID" & "|" & $objWMI_Variable.DeviceID & "|" & "[string]" & @CRLF & _ "ErrorCleared" & "|" & $objWMI_Variable.ErrorCleared & "|" & "[boolean]" & @CRLF & _ "ErrorDescription" & "|" & $objWMI_Variable.ErrorDescription & "|" & "[string]" & @CRLF & _ "InstallDate" & "|" & $objWMI_Variable.InstallDate & "|" & "[datetime]" & @CRLF & _ "IsLinear" & "|" & $objWMI_Variable.IsLinear & "|" & "[boolean]" & @CRLF & _ "LastErrorCode" & "|" & $objWMI_Variable.LastErrorCode & "|" & "[uint32]" & @CRLF & _ "LowerThresholdCritical" & "|" & $objWMI_Variable.LowerThresholdCritical & "|" & "[sint32]" & @CRLF & _ "LowerThresholdFatal" & "|" & $objWMI_Variable.LowerThresholdFatal & "|" & "[sint32]" & @CRLF & _ "LowerThresholdNonCritical" & "|" & $objWMI_Variable.LowerThresholdNonCritical & "|" & "[sint32]" & @CRLF & _ "MaxReadable" & "|" & $objWMI_Variable.MaxReadable & "|" & "[sint32]" & @CRLF & _ "MinReadable" & "|" & $objWMI_Variable.MinReadable & "|" & "[sint32]" & @CRLF & _ "Name" & "|" & $objWMI_Variable.Name & "|" & "[string]" & @CRLF & _ "NominalReading" & "|" & $objWMI_Variable.NominalReading & "|" & "[sint32]" & @CRLF & _ "NormalMax" & "|" & $objWMI_Variable.NormalMax & "|" & "[sint32]" & @CRLF & _ "NormalMin" & "|" & $objWMI_Variable.NormalMin & "|" & "[sint32]" & @CRLF & _ "PNPDeviceID" & "|" & $objWMI_Variable.PNPDeviceID & "|" & "[string]" & @CRLF & _ "PowerManagementCapabilities" & "|" & $objWMI_Variable.PowerManagementCapabilities & "|" & "[uint16]" & @CRLF & _ "PowerManagementSupported" & "|" & $objWMI_Variable.PowerManagementSupported & "|" & "[boolean]" & @CRLF & _ "Resolution" & "|" & $objWMI_Variable.Resolution & "|" & "[uint32]" & @CRLF & _ "Status" & "|" & $objWMI_Variable.Status & "|" & "[string]" & @CRLF & _ "StatusInfo" & "|" & $objWMI_Variable.StatusInfo & "|" & "[uint16]" & @CRLF & _ "SystemCreationClassName" & "|" & $objWMI_Variable.SystemCreationClassName & "|" & "[string]" & @CRLF & _ "SystemName" & "|" & $objWMI_Variable.SystemName & "|" & "[string]" & @CRLF & _ "Tolerance" & "|" & $objWMI_Variable.Tolerance & "|" & "[sint32]" & @CRLF & _ "UpperThresholdCritical" & "|" & $objWMI_Variable.UpperThresholdCritical & "|" & "[sint32]" & @CRLF & _ "UpperThresholdFatal" & "|" & $objWMI_Variable.UpperThresholdFatal & "|" & "[sint32]" & @CRLF & _ "UpperThresholdNonCritical" & "|" & $objWMI_Variable.UpperThresholdNonCritical & "|" & "[sint32]" $i+=1 Next ConsoleWrite($strWMI_QueryResult & @CRLF) _ArrayAdd($arrWin32_TemperatureProbe, $strWMI_QueryResult) ; I'll wait for an answer... See you later :) If @error Then __ConsoleWrite("Error inserting item #" & $i & " in the $arrWin32_TemperatureProbe array.", @error, 9999) Else If $blnCustomArrayDisplay Then _ArrayDisplay($arrWin32_TemperatureProbe, "Win32_TemperatureProbe:", "", 64 + 32 + 4, "|", "VARIABLE NAME|ACTUAL VALUE|ENGINEERING UNIT", 350, 0xD3D3D3) If @error Then __ConsoleWrite("Error displaying the $arrWin32_TemperatureProbe array.", @error, 9999) EndIf EndIf If $blnReturnEU = False Then _ArrayColDelete($arrWin32_TemperatureProbe, 2) If @error Then __ConsoleWrite("Error deleting the column #2 of $arrWin32_TemperatureProbe array.") EndIf EndIf If IsArray($arrWin32_TemperatureProbe) Then Return $arrWin32_TemperatureProbe Else Return False EndIf EndIf EndIf EndIf EndIf EndFunc And I get this error ( undocumented in the Help File on _ArrayAdd() function ): [15/09/2017 10:24:46] : Error inserting item #4 in the $arrWin32_TemperatureProbe array. > Error: 0 Adding a ConsoleWrite() before the _ArrayAdd() function, I can see the content of $strWMI_QueryResult, and, here it is: QUERY RESULT|# 0|/ Accuracy|32768|[sint32] Availability||[uint16] Caption|Sensore numerico|[string] ConfigManagerErrorCode||[uint32] ConfigManagerUserConfig||[boolean] CreationClassName|Win32_TemperatureProbe|[string] CurrentReading||[sint32] Description|CPU Thermal Probe|[string] DeviceID|root\cimv2 0|[string] ErrorCleared||[boolean] ErrorDescription||[string] InstallDate||[datetime] IsLinear||[boolean] LastErrorCode||[uint32] LowerThresholdCritical||[sint32] LowerThresholdFatal||[sint32] LowerThresholdNonCritical||[sint32] MaxReadable|1270|[sint32] MinReadable|64266|[sint32] Name|Sensore numerico|[string] NominalReading||[sint32] NormalMax||[sint32] NormalMin||[sint32] PNPDeviceID||[string] PowerManagementCapabilities||[uint16] PowerManagementSupported||[boolean] Resolution|1000|[uint32] Status|Unknown|[string] StatusInfo||[uint16] SystemCreationClassName|Win32_ComputerSystem|[string] SystemName|DESKTOP-25LFPVU|[string] Tolerance|32768|[sint32] UpperThresholdCritical||[sint32] UpperThresholdFatal||[sint32] UpperThresholdNonCritical||[sint32]QUERY RESULT|# 1|/ Accuracy|32768|[sint32] Availability||[uint16] Caption|Sensore numerico|[string] ConfigManagerErrorCode||[uint32] ConfigManagerUserConfig||[boolean] CreationClassName|Win32_TemperatureProbe|[string] CurrentReading||[sint32] Description|True Ambient Thermal Probe|[string] DeviceID|root\cimv2 1|[string] ErrorCleared||[boolean] ErrorDescription||[string] InstallDate||[datetime] IsLinear||[boolean] LastErrorCode||[uint32] LowerThresholdCritical||[sint32] LowerThresholdFatal||[sint32] LowerThresholdNonCritical||[sint32] MaxReadable|1270|[sint32] MinReadable|64266|[sint32] Name|Sensore numerico|[string] NominalReading||[sint32] NormalMax||[sint32] NormalMin||[sint32] PNPDeviceID||[string] PowerManagementCapabilities||[uint16] PowerManagementSupported||[boolean] Resolution|1000|[uint32] Status|Unknown|[string] StatusInfo||[uint16] SystemCreationClassName|Win32_ComputerSystem|[string] SystemName|DESKTOP-25LFPVU|[string] Tolerance|32768|[sint32] UpperThresholdCritical||[sint32] UpperThresholdFatal||[sint32] UpperThresholdNonCritical||[sint32]QUERY RESULT|# 2|/ Accuracy|32768|[sint32] Availability||[uint16] Caption|Sensore numerico|[string] ConfigManagerErrorCode||[uint32] ConfigManagerUserConfig||[boolean] CreationClassName|Win32_TemperatureProbe|[string] CurrentReading||[sint32] Description|Memory Module Thermal Probe|[string] DeviceID|root\cimv2 2|[string] ErrorCleared||[boolean] ErrorDescription||[string] InstallDate||[datetime] IsLinear||[boolean] LastErrorCode||[uint32] LowerThresholdCritical||[sint32] LowerThresholdFatal||[sint32] LowerThresholdNonCritical||[sint32] MaxReadable|1270|[sint32] MinReadable|64266|[sint32] Name|Sensore numerico|[string] NominalReading||[sint32] NormalMax||[sint32] NormalMin||[sint32] PNPDeviceID||[string] PowerManagementCapabilities||[uint16] PowerManagementSupported||[boolean] Resolution|1000|[uint32] Status|Unknown|[string] StatusInfo||[uint16] SystemCreationClassName|Win32_ComputerSystem|[string] SystemName|DESKTOP-25LFPVU|[string] Tolerance|32768|[sint32] UpperThresholdCritical||[sint32] UpperThresholdFatal||[sint32] UpperThresholdNonCritical||[sint32]QUERY RESULT|# 3|/ Accuracy|32768|[sint32] Availability||[uint16] Caption|Sensore numerico|[string] ConfigManagerErrorCode||[uint32] ConfigManagerUserConfig||[boolean] CreationClassName|Win32_TemperatureProbe|[string] CurrentReading||[sint32] Description|Video Card Thermal Probe|[string] DeviceID|root\cimv2 3|[string] ErrorCleared||[boolean] ErrorDescription||[string] InstallDate||[datetime] IsLinear||[boolean] LastErrorCode||[uint32] LowerThresholdCritical||[sint32] LowerThresholdFatal||[sint32] LowerThresholdNonCritical||[sint32] MaxReadable|1270|[sint32] MinReadable|64266|[sint32] Name|Sensore numerico|[string] NominalReading||[sint32] NormalMax||[sint32] NormalMin||[sint32] PNPDeviceID||[string] PowerManagementCapabilities||[uint16] PowerManagementSupported||[boolean] Resolution|1000|[uint32] Status|Unknown|[string] StatusInfo||[uint16] SystemCreationClassName|Win32_ComputerSystem|[string] SystemName|DESKTOP-25LFPVU|[string] Tolerance|32768|[sint32] UpperThresholdCritical||[sint32] UpperThresholdFatal||[sint32] UpperThresholdNonCritical||[sint32]  Could please anyone help me out? Thanks in advance Francesco Edited September 15, 2017 by FrancescoDiMuro Wrong Code! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette  Link to comment Share on other sites More sharing options...
SlackerAl Posted September 15, 2017 Share Posted September 15, 2017 The code you've pasted does not contain the line the error occurs in (no mention of $arrWin32_TemperatureProbe in your function). I suggest the first step to solving this is to analyse all your variables and write a short replicator of your problem. Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 15, 2017 Author Share Posted September 15, 2017 Hi @SlackerAl! I updated the code! I attached wrong code before, sorry! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette  Link to comment Share on other sites More sharing options...
SlackerAl Posted September 15, 2017 Share Posted September 15, 2017 Can I refer you to my second comment? :-) The only other help I can be is it seems very likely to me that your query data is not appropriately formatted to be added to an array e.g. \ ' " data in it perhaps? Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 15, 2017 Author Share Posted September 15, 2017 Why ' , \ or " should affect the insert into the array? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette  Link to comment Share on other sites More sharing options...
BrewManNH Posted September 15, 2017 Share Posted September 15, 2017 Try changing these lines to this. ;` from this _ArrayAdd($arrWin32_TemperatureProbe, $strWMI_QueryResult) ; I'll wait for an answer... See you later :) If @error Then __ConsoleWrite("Error inserting item #" & $i & " in the $arrWin32_TemperatureProbe array.", @error, 9999) ;` to this _ArrayAdd($arrWin32_TemperatureProbe, $strWMI_QueryResult) ; I'll wait for an answer... See you later :) If @error Then $error = @error __ConsoleWrite("Error inserting item #" & $i & " in the $arrWin32_TemperatureProbe array.", $error, 9999) See if the error message is different, and then see what it refers to. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 15, 2017 Author Share Posted September 15, 2017 @BrewManNH Thank you for replying No changes at the error code by the way... Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette  Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 19, 2017 Author Share Posted September 19, 2017 Bump Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette  Link to comment Share on other sites More sharing options...
BrewManNH Posted September 19, 2017 Share Posted September 19, 2017 Can you post a working example script so we can test this? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator 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