我有一个HTA文件,可以在其中调整窗口的大小,以便在屏幕的右侧进行调整。
在某些计算机(约120台计算机中的10台)上,我在我们希望用户使用分辨率(移动或调整窗口大小)的行上收到类型不匹配错误。我将获得的值不是整数,或者也许不是。
所有PC都安装在Win 7上,我看不出它们之间有什么区别(但是似乎有区别)
这是在“ Window_onLoad”子窗口中完成的:
Sub Window_onLoad()
Dim per
Set wshShell = CreateObject("Wscript.Shell")
Set getOSVersion = wshShell.Exec("%comspec% /c ver")
version = getOSVersion.StdOut.ReadAll
Select Case True
Case InStr(version, "n 5.") > 1 : GetOS = "XP"
'WIN XP CODE HERE...
Case InStr(version, "n 6.") > 1 : GetOS = "Vista/7"
'<--- Win 7
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
这时我们将分辨率设为整数,并且在99%的情况下都能正常工作。
如果我们没有得到分辨率,我们会尝试另一种方法来获得第一个屏幕的分辨率。
If IsNumeric(intHorizontal) And IsNumeric(intVertical) Then
Else
MsgBox "2"
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
If IsNumeric(intHorizontal) And IsNumeric(intVertical) Then
在这里,我们尝试第三种方式。
Else
MsgBox "3"
Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor2'",,0)
For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
End If
End If
这里我们应该有分辨率,我们只需计算正确的位置即可。
intLeft = intHorizontal - 300 ' (intHorizontal + 800)/ 2
intTop = 1 ' (intVertical + 400) / 4
Window.resizeTo 300, intVertical - 40 '<--- HERE we get the error
Window.moveTo intLeft, intTop
'Some additional code here...
Case InStr(version, "n 10.") > 1 : GetOS = "W10"
'WIN 10 code here ...
Case Else : GetOS = "Unknown"
MsgBox "Not Supported ( Unknown OS)"
End Select
'Some addtitonal code here...
End Sub
您知道什么可能是问题。为什么我完全会出错?
#正如Ansgar Wiechers所建议的那样,我在有问题的PC上运行了一个简单的vb:
msgbox "TEST"
strComputer = "."
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
For Each objItem In colItems
intHorizontal = objItem.ScreenWidth
intVertical = objItem.ScreenHeight
Next
msgbox TypeName(intHorizontal)
msgbox TypeName(intVertical)
msgbox (intHorizontal)
msgbox (intVertical)
我得到了:
测试/
空值/
空值/
错误:intHorizontal
/