Jump to content
FrancescoDiMuro

Error 0 from _ArrayAdd()

Recommended Posts

FrancescoDiMuro

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:

Func _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 by FrancescoDiMuro
Wrong Code!

Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
SlackerAl

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.

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Hi @SlackerAl!

I updated the code! I attached wrong code before, sorry! :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
SlackerAl

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.

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Why ' , \ or " should affect the insert into the array? :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites
FrancescoDiMuro

@BrewManNH

Thank you for replying :)

No changes at the error code by the way... :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Bump :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
BrewManNH

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 Gude
How 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

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

  • Similar Content

    • Tersion
      By Tersion
      Here the this wiki page with list of available UDFs for data compression. For my tasks I only need ZIP support, so I started looking at pure AutoIt UDFs without any 3rd party dlls. And found out that most of available realizations uses standard ("native method") Windows dll - "zipfldr.dll". So for now I chose ZIP UDF by wraithdu. I've tested it on Windows 7 (x64) and it seem works fine. But here the comment from another topic where user says that Windows 10 discontinued support of "zipfldr.dll". Now I confused. I don't have around any Windows 10 machine to tested it. So maybe someone could confirm or deny that? Or maybe would better to switch to UDF with 7zip dll?
      I need an advice...
    • TheSaint
      By TheSaint
      Here is the bare bones of a UDF I have started work on.
      Mostly just a proof of concept at this stage, and still need to add some functions and dress the UDF up a bit ... to look like a UDF ... though it has my own distinct styling, especially as I have never really developed a UDF before now .... used plenty and modified plenty though. I've even invented my own UDF variable naming convention, which I am sure some of you will be aghast at. I work with what feels best for me, but others are free to adapt if they wish.
      The idea is to emulate the simplicity of INI files, but gain the benefits of SQL.
      Two scripts are provided.
      (1) The UDF, a work in progress - SimpleSQL_UDF.au3
      (2) An example or testing script - UDF_Test.au3
      Another first for me, is creating a 2D array from scratch, never done that before, that I can recall ... never had a need, and even for 1 dimension arrays, for a long time now, I have just used _StringSplit to create them. So I needed a bit of a refresher course, which my good buddy @TheDcoder assisted me with ... not without some angst I might add. LOL
      SimpleSQL_UDF.zip  (12 downloads previously)
      (I have now completed all the functions I intended to. My next update will be a big improvement, bringing things more inline with my latest INItoSQL DB program changes.)
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      Hopefully the usage is self-evident ... just change the Job number variable in the UDF_Test.au3 file to check the existing functions out.
      Enjoy!
      P.S. This is also related to a new program I have just finished and uploaded - INItoSQL DB
    • xtcislove
      By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
    • Gowrisankar
      By Gowrisankar
      Dear members, 
      I am working on a project where, emails from outlook are to be read and moved to various folders within the mailbox, based on the content of the emails.
      I used the below code for moving mails. It works fine when I run it against individual mail ids. But when I run it on Shared mailbox, the mails are not moved to respective folders.
      _OL_ItemMove($oOutlook, $sEntryId, Default, $sDestinationFolder) The value of $sEntryId is saved in an excel report initially. The current process reads the $sEntryId from the excel and passes it to "_OL_ItemMove" statement.
      Requesting the guidance of the forum members in this issue.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
      The replace does work everywhere in the document, but, it does not work in Headers or Footers.
      Am I missing something or am I forced to use the code below?
      I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
      Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance


      Best Regards.
×