Sign in to follow this  
Followers 0
Emiel Wieldraaijer

_ArrayCreate -> Count the array

6 posts in this topic

Hi All,

#include <Array.au3>

Dim $avArray
$avArray = _ArrayCreate("JPM", "Holger", "Jon", "Larry", "Jeremy", "Valik", "Cyberslug", "Nutster", "Tylo", "JdeB")
msgbox (0, "Count this array ?", $avArray[0])
Exit

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

Thnx

Emiel


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites



Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@JerryD

Thnx exactly what i needed ..

Best regards,

Emiel


Best regards,Emiel Wieldraaijer

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
Sign in to follow this  
Followers 0