【问题标题】:How can I fix type mismatch error on window.moveTo with VBScript?如何使用 VBScript 修复 window.moveTo 上的类型不匹配错误?
【发布时间】:2017-11-02 16:50:02
【问题描述】:

这里的一切在 Windows 7 上运行良好。在 Windows 10 上,window.MoveTo intLeft, intTop 出现类型不匹配错误。

Sub Window_OnLoad
    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
    intLeft = (intHorizontal - 670) / 2
    intTop = (intVertical - 325) / 2
    window.ResizeTo 670,325
    window.MoveTo intLeft, intTop
End Sub

【问题讨论】:

  • 您确定intLeftintTop 是整数而不是浮点数吗?
  • 显然他们都是 Null。

标签: vbscript windows-10 hta


【解决方案1】:

所以问题是objWMIService。我猜它在 Windows 10 中的工作方式不一样。

这是一个我发现似乎工作得很好的函数。

array_ScreenRes = GetScreenResolution
intHorizontal = array_ScreenRes(0)
intVertical = array_ScreenRes(1)

Function GetScreenResolution()
    Set oIE = CreateObject("InternetExplorer.Application")
    With oIE
        .Navigate("about:blank")
        Do Until .ReadyState = 4: WScript.Sleep 100: Loop
        width = .Document.ParentWindow.Screen.Width
        height = .document.ParentWindow.Screen.Height
    End With

    oIE.Quit
    GetScreenResolution = Array(width, height)
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    相关资源
    最近更新 更多