GrahamTheDev
GrahamTheDev

Reputation: 24815

How do I use this query in vb.net - I cannot get my head around converting from c# to vb.net

ObjectQuery query = new ObjectQuery("Select * FROM Win32_Battery");

foreach (ManagementObject o in new ManagementObjectSearcher(query).Get())
{
    uint level = (uint)o.Properties["EstimatedChargeRemaining"].Value;
} 

Simple in c# - really cannot get my head around it in vb.net -> tried online and manual conversion and keep getting stuck

For Each o As ManagementObject In New ManagementObjectSearcher(query2) <- getting stuck at this point I think -> not sure how to do the .get

If anyone can help me convert that would be wonderful - preferably the full conversion as I have found parts of my answer all over and they all seem to 'miss a step'

Upvotes: 0

Views: 260

Answers (2)

Shell
Shell

Reputation: 6849

Have you tried developerFusion site to covert your code. The following code has converted from developer fusion.

Dim query As New ObjectQuery("Select * FROM Win32_Battery")

For Each o As ManagementObject In New ManagementObjectSearcher(query).[Get]()
    Dim level As UInteger = CUInt(o.Properties("EstimatedChargeRemaining").Value)
Next

Upvotes: 0

jmcilhinney
jmcilhinney

Reputation: 54417

Pretty much exactly as you'd expect:

Dim query As New ObjectQuery("Select * FROM Win32_Battery")

For Each o As ManagementObject In New ManagementObjectSearcher(query).Get()
    Dim level = CUInt(o.Properties("EstimatedChargeRemaining").Value)
Next

Upvotes: 3

Related Questions