Jump to content

_ArrayCreate -> Count the array


Recommended Posts

Link to comment
Share on other sites

Hi Emiel,

Shouldn't $avArray[0] return the amount of items in the array ?

No specification or standard states that _ArrayCreate() should use the 1st element as a count of total elements. _ArrayCreate() predates the newer syntax of array creation so you may like to use it instead.

Global $avArray[11] = [10, "JPM", "Holger", "Jon", "Larry", "Jeremy", _
                           "Valik", "Cyberslug", "Nutster", "Tylo", "JdeB"]

For $i = 0 To $avArray[0]
    MsgBox(0, $i, $avArray[$i], 1)
Next
Link to comment
Share on other sites

Hi Bert and Mhz,

thnx

Mhz this is not a solution to me

maybe there is another solution to my problem

Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $wbemFlags = $wbemFlagReturnImmediately + $wbemFlagForwardOnly
Global $strComputer = @ComputerName
Global $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
Global $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlags)

i want to create an array of $objItem.LoadPercentage, can this be done ? where $Array[0] is the amount of values

Thnx

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Link to comment
Share on other sites

#include <array.au3>
Const $wbemFlagReturnImmediately = 0x10
Const $wbemFlagForwardOnly = 0x20
Const $strComputer = 'localhost'
Dim $RetAry[1]
$RetAry[0] = 0

$objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\root\CIMV2')
$colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then
    For $objItem In $colItems
        ReDim $RetAry[$RetAry[0]+2]
        $RetAry[0] += 1
        $RetAry[$RetAry[0]] = $objItem.LoadPercentage
    Next
    _ArrayDisplay ( $RetAry )
Else
    MsgBox(0, 'WMI Output', 'No WMI Objects Found for class: ' & 'Win32_Processor')
EndIf

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...