Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Why are my objects gone after I For ... loop through them?

$
0
0

I have what I hope is a simple noob programming question.

 

In the code snippet below, I make an WMI query and store the results in $objItems. Then I run through $objItems with a For loop.

 

If I try to re-use $objItems after I do this, the date stored in it isn't there. I have to re-run the WMI query to have valid data.

 

Is that normal? Or should I query, store the data I need to variables, and then be able to reuse them?

 

Example workflow: Query WMI, store to $objItems. Loop through and find there are no disks matching my variables that have partitions. After I have more functions to create partitions, but I have to re-query WMI to reuse the same $objItems array because all the objects are now null.

$objItems = $objWMI.ExecQuery("SELECT * FROM CIM_DiskDrive", "WQL", 0x10 + 0X20); query WMI for disk information If IsObj($objItems) Then ; we check for existing partitions and clean them if needed, then reboot     For $objItem In $objItems         If $objItem.SCSIBus = $sSysDiskBus And $objItem.SCSIPort = $sSysDiskPrt And $objItem.InterfaceType = "SCSI" And $objItem.Partitions <> 0 Then             _cleanDisk($objItem.Index); will reboot when it's done         EndIf     Next EndIf

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>