|
-
Nov 4th, 2005, 09:39 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Run-time error '6': Overflow
I colored the line that errors in red. I have NO idea what the hell is wrong. :'(
VB Code:
Option Explicit
Type TypeDiskDrive
InterfaceType As String
Partitions As Long
Size As Long
Status As String
End Type
Public DiskDrives As TypeDiskDrive
Sub Main()
Debug.Print "MDiskDrives->Main();"
End Sub
Public Sub Win32_DiskDrive()
Debug.Print "MDiskDrives->Win32_DiskDrive();"
Dim CIMV2 As Object
Dim Result As Object
Dim Row As Object
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Partitions, Size, Status FROM Win32_DiskDrive", "WQL", &H10 + &H20)
For Each Row In Result
MsgBox Row.Size
DiskDrives.InterfaceType = Row.InterfaceType
DiskDrives.Partitions = Row.Partitions
[COLOR=Red]DiskDrives.Size = Row.Size[/COLOR]
DiskDrives.Status = Row.Status
Next
End Sub
Last edited by frozen; Nov 5th, 2005 at 03:24 AM.
Reason: :D
-
Nov 4th, 2005, 10:00 PM
#2
Re: Run-time error '6': Overflow
If I remember correctly the Row.Size would be a 64-bit Integer while a Long is just 32-bit. Try to declare your Size member as Currency since that is basically a 64-bit integer however when you print it is divided with 10000 when it is displayed. But you can do some calculation around that.
-
Nov 4th, 2005, 10:30 PM
#3
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
Now I am getting Run-time error '-2147217385 (80041017)': Automation error on the red For Each...
VB Code:
Option Explicit
Public Type TypeNetworkAdapter
Name As String
End Type
Public NetworkAdapters As TypeNetworkAdapter
Sub Main()
Debug.Print "MNetworkAdapters->Main();"
End Sub
Public Sub Win32_NetworkAdapters()
Debug.Print "MNetworkAdapters->Win32_NetworkAdapter();"
Dim CIMV2 As Object
Dim Result As Object
Dim Row As Object
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
[COLOR=Red]For Each Row In Result[/COLOR]
If Row.InterfaceType = "Ethernet 802.3" Then
NetworkAdapters.Name = Row.Name
End If
Next
End Sub
-
Nov 4th, 2005, 10:53 PM
#4
Hyperactive Member
Re: Run-time error '6': Overflow
i guess that row cannot be a member of result. Try to find out what kind of value (int,lng or byte) you get from CIMV2 and what is Row.
I think it has to do with different types.
-
Nov 4th, 2005, 11:05 PM
#5
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
-
Nov 4th, 2005, 11:15 PM
#6
Re: Run-time error '6': Overflow
Scriptomatic2 does it like this:
Save it as a .vbs file, and run with Internet Explorer, or use Cscript.exe
VB Code:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "AdapterType: " & objItem.AdapterType
WScript.Echo "AdapterTypeId: " & objItem.AdapterTypeId
WScript.Echo "AutoSense: " & objItem.AutoSense
WScript.Echo "Availability: " & objItem.Availability
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
WScript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
WScript.Echo "CreationClassName: " & objItem.CreationClassName
WScript.Echo "Description: " & objItem.Description
WScript.Echo "DeviceID: " & objItem.DeviceID
WScript.Echo "ErrorCleared: " & objItem.ErrorCleared
WScript.Echo "ErrorDescription: " & objItem.ErrorDescription
WScript.Echo "Index: " & objItem.Index
WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
WScript.Echo "Installed: " & objItem.Installed
WScript.Echo "LastErrorCode: " & objItem.LastErrorCode
WScript.Echo "MACAddress: " & objItem.MACAddress
WScript.Echo "Manufacturer: " & objItem.Manufacturer
WScript.Echo "MaxNumberControlled: " & objItem.MaxNumberControlled
WScript.Echo "MaxSpeed: " & objItem.MaxSpeed
WScript.Echo "Name: " & objItem.Name
WScript.Echo "NetConnectionID: " & objItem.NetConnectionID
WScript.Echo "NetConnectionStatus: " & objItem.NetConnectionStatus
strNetworkAddresses = Join(objItem.NetworkAddresses, ",")
WScript.Echo "NetworkAddresses: " & strNetworkAddresses
WScript.Echo "PermanentAddress: " & objItem.PermanentAddress
WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
strPowerManagementCapabilities = Join(objItem.PowerManagementCapabilities, ",")
WScript.Echo "PowerManagementCapabilities: " & strPowerManagementCapabilities
WScript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
WScript.Echo "ProductName: " & objItem.ProductName
WScript.Echo "ServiceName: " & objItem.ServiceName
WScript.Echo "Speed: " & objItem.Speed
WScript.Echo "Status: " & objItem.Status
WScript.Echo "StatusInfo: " & objItem.StatusInfo
WScript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
WScript.Echo "SystemName: " & objItem.SystemName
WScript.Echo "TimeOfLastReset: " & WMIDateStringToDate(objItem.TimeOfLastReset)
WScript.Echo
Next
Next
Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function
-
Nov 4th, 2005, 11:37 PM
#7
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
-
Nov 4th, 2005, 11:55 PM
#8
Hyperactive Member
Re: Run-time error '6': Overflow
 Originally Posted by frozen
They are all Objects :|
Objects can contain different types.(variants, strings, integers, my own defined types, etc....)
You need to convert them probably to one and another.
-
Nov 4th, 2005, 11:57 PM
#9
Re: Run-time error '6': Overflow
 Originally Posted by frozen
They are all Objects :|
After this line
VB Code:
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
go in to the Immediate window and type
and see what it says.
-
Nov 4th, 2005, 11:58 PM
#10
Re: Run-time error '6': Overflow
 Originally Posted by hassa046
Objects can contain different types.(variants, strings, integers, my own defined types, etc....)
You need to convert them probably to one and another.
Objects are generic objects whos interface is obtained after they are cast to specific objects. They cannot "contain" other types - that is what Variants do.
-
Nov 5th, 2005, 12:05 AM
#11
Hyperactive Member
Re: Run-time error '6': Overflow
Hmm. Are you sure?
I have a class with several function (like Autostr) Class1.
Together with other classes it has become an object. Lets say Program1
In program 2 i want to use an autogenerated string called Autostr
First i make an empty object
Dim P1 as object
Set P1 = createobject(Program1.Class1)
So P1 becomes the class1 object
but when i use P1 as P1.Autostr then it gives me a string as result.
Thats what i ment.
-
Nov 5th, 2005, 12:08 AM
#12
Re: Run-time error '6': Overflow
That's completely different. Upon your "Set P1 = " line you cast the generic P1 object to a reference to Program1.Class1 and obtain the interface for that class (The interface contains all the methods, properties etc). Autostr must be a string-typed member of Class1.
Variants, on the other hand, CAN contain other variables.
-
Nov 5th, 2005, 12:11 AM
#13
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
-
Nov 5th, 2005, 12:40 AM
#14
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
 Originally Posted by frozen
Run-time error '-2147217385 (80041017)': Automation error on the red For Each...
VB Code:
Option Explicit
Public Type TypeNetworkAdapter
Name As String
End Type
Public NetworkAdapters As TypeNetworkAdapter
Sub Main()
Debug.Print "MNetworkAdapters->Main();"
End Sub
Public Sub Win32_NetworkAdapters()
Debug.Print "MNetworkAdapters->Win32_NetworkAdapter();"
Dim CIMV2 As Object
Dim Result As Object
Dim Row As Object
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
[COLOR=Red]For Each Row In Result[/COLOR]
If Row.InterfaceType = "Ethernet 802.3" Then
NetworkAdapters.Name = Row.Name
End If
Next
End Sub
Still stuck here...
-
Nov 5th, 2005, 12:53 AM
#15
Hyperactive Member
Re: Run-time error '6': Overflow
Try this:
VB Code:
Option Explicit
Public Type TypeNetworkAdapter
Name As String
End Type
Public NetworkAdapters As TypeNetworkAdapter
Sub Main()
Debug.Print "MNetworkAdapters->Main();"
End Sub
Public Sub Win32_NetworkAdapters()
Debug.Print "MNetworkAdapters->Win32_NetworkAdapter();"
Dim CIMV2 As Object
Dim Result As Variant
Dim Row As Variant
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set Result = CIMV2.ExecQuery("SELECT InterfaceType, Name FROM
Win32_NetworkAdapter", "WQL", &H10 + &H20)
For Each Row In Result
If Row.InterfaceType = "Ethernet 802.3" Then
NetworkAdapters.Name = Row.Name
End If
Next
End Sub
-
Nov 5th, 2005, 12:57 AM
#16
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
Changes nothing
-
Nov 5th, 2005, 01:19 AM
#17
Re: Run-time error '6': Overflow
The error is because the Win32_NetworkAdapter WMI object doesn't have an InterfaceType property so the result is a NULL object and you can't use a For Each loop on that.
EDIT: What you should look for is the AdapterType instead. So the end of your code should look like this:
VB Code:
Set Result = CIMV2.ExecQuery("SELECT AdapterType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
For Each Row In Result
If Row.AdapterType = "Ethernet 802.3" Then
NetworkAdapters.Name = Row.Name
End If
Next
Last edited by Joacim Andersson; Nov 5th, 2005 at 01:26 AM.
-
Nov 5th, 2005, 01:27 AM
#18
Hyperactive Member
Re: Run-time error '6': Overflow
http://msdn.microsoft.com/library/de...r_hardware.asp
both declared as object
VB Code:
Set CIMV2 = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")
Set results = CIMV2.ExecQuery("SELECT AdapterType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
I saw that Joacim also found the error.
-
Nov 5th, 2005, 01:30 AM
#19
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
-
Nov 5th, 2005, 01:52 AM
#20
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
-
Nov 5th, 2005, 01:52 AM
#21
Re: Run-time error '6': Overflow
 Originally Posted by Joacim Andersson
The error is because the Win32_NetworkAdapter WMI object doesn't have an InterfaceType property so the result is a NULL object and you can't use a For Each loop on that.
EDIT: What you should look for is the AdapterType instead. So the end of your code should look like this:
VB Code:
Set Result = CIMV2.ExecQuery("SELECT AdapterType, Name FROM Win32_NetworkAdapter", "WQL", &H10 + &H20)
For Each Row In Result
If Row.AdapterType = "Ethernet 802.3" Then
NetworkAdapters.Name = Row.Name
End If
Next
I guess that works, but you're still using For Each...?
-
Nov 5th, 2005, 01:53 AM
#22
Re: Run-time error '6': Overflow
-
Nov 5th, 2005, 02:02 AM
#23
Re: Run-time error '6': Overflow
 Originally Posted by penagate
I guess that works, but you're still using For Each...?
Yes... Because I use the correct SQL statement in the call I get a correct object and you can use For Each on WMI objects.
-
Nov 5th, 2005, 02:04 AM
#24
Re: Run-time error '6': Overflow
Oh, I didn't notice the SQL statement was changed. I understand now
-
Nov 5th, 2005, 02:29 AM
#25
Thread Starter
Hyperactive Member
Re: Run-time error '6': Overflow
This is getting off topic but I think it will be my last question so I won't make a new topic for it.
I'm now trying to detect the mouse, Win32_PointingDevice gives me two and I see no item to seperate the _real_ one from the _fake_ one
Code:
Availability:
Caption: HID-compliant mouse
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_PointingDevice
Description: HID-compliant mouse
DeviceID: HID\VID_046D&PID_C309&MI_01&COL03\7&36E55074&0&0002
DeviceInterface: 162
DoubleSpeedThreshold: 6
ErrorCleared:
ErrorDescription:
Handedness: 2
HardwareType: HID-compliant mouse
InfFileName: msmouse.inf
InfSection: HID_Mouse_Inst
IsLocked:
LastErrorCode:
Manufacturer: Microsoft
Name: HID-compliant mouse
NumberOfButtons: 5
PNPDeviceID: HID\VID_046D&PID_C309&MI_01&COL03\7&36E55074&0&0002
PointingType: 2
PowerManagementCapabilities:
PowerManagementSupported: False
QuadSpeedThreshold: 10
Resolution:
SampleRate:
Status: OK
StatusInfo:
Synch:
SystemCreationClassName: Win32_ComputerSystem
SystemName: SAM
Availability:
Caption: Microsoft USB IntelliMouse Explorer 3.0
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_PointingDevice
Description: Microsoft USB IntelliMouse Explorer 3.0
DeviceID: USB\VID_045E&PID_0047\5&DF9F058&0&2
DeviceInterface: 162
DoubleSpeedThreshold: 6
ErrorCleared:
ErrorDescription:
Handedness: 2
HardwareType: Microsoft USB IntelliMouse Explorer 3.0
InfFileName: input.inf
InfSection: HID_Inst
IsLocked:
LastErrorCode:
Manufacturer: Microsoft
Name: Microsoft USB IntelliMouse Explorer 3.0
NumberOfButtons: 5
PNPDeviceID: USB\VID_045E&PID_0047\5&DF9F058&0&2
PointingType: 2
PowerManagementCapabilities:
PowerManagementSupported: False
QuadSpeedThreshold: 10
Resolution:
SampleRate:
Status: OK
StatusInfo:
Synch:
SystemCreationClassName: Win32_ComputerSystem
SystemName: SAM
-
Nov 5th, 2005, 02:42 AM
#26
Re: Run-time error '6': Overflow
I think that gives you the drivers. As to which device is actually plugged in, you'd need to enumerate all available Devices of that type, I think.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|