Results 1 to 2 of 2

Thread: [RESOLVED] Loop though an object getting key and value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Resolved [RESOLVED] Loop though an object getting key and value

    I am looking to replace something like
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim Row As Object
    3.     For Each Row In GetObject("winmgmts:\\127.0.0.1\root\CIMV2"). _
    4.       ExecQuery("SELECT ScreenHeight,ScreenWidth FROM Win32_DesktopMonitor", "WQL", &H10 + &H20)
    5.         Debug.Print "ScreenHeigh", Row.ScreenHeight
    6.         Debug.Print "ScreenWidth", Row.ScreenWidth
    7.     Next
    8. End Sub
    with
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim Row As Object
    3.     Dim Col As Object
    4.     For Each Row In GetObject("winmgmts:\\127.0.0.1\root\CIMV2"). _
    5.       ExecQuery("SELECT ScreenHeight,ScreenWidth FROM Win32_DesktopMonitor", "WQL", &H10 + &H20)
    6.         For Each Col In Row
    7.             Debug.Print Key(Col), Value(Col)
    8.         Next
    9.     Next
    10. End Sub

    Second example don't wanna work.

    Edit: fixed a typ0.
    Last edited by frozen; Apr 8th, 2006 at 12:24 AM.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Loop though an object getting key and value

    Try:
    VB Code:
    1. Dim Rows As Object
    2.   Dim Row As Object
    3.   Dim Col As Object
    4.   Dim winMgmts As Object
    5.  
    6.   Set winMgmts = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
    7.  
    8.   Set Rows = winMgmts. _
    9.     ExecQuery("SELECT ScreenHeight,ScreenWidth FROM Win32_DesktopMonitor", "WQL", &H10 + &H20)
    10.    
    11.   For Each Row In Rows
    12.     For Each Col In Row.Properties_
    13.       Debug.Print Col.Name, Col.Value
    14.     Next
    15.   Next
    Regards,

    - Aaron.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width