Post Reply

Forums -> UltraMon™ SDK -> reference to a monitor in a collection
Patrick McKinley   2008-11-24 03:49
Hi,
I'm very much a novice to vbscript...but thought this script would work. It fails on the Set curMon statement due to an invalid procedure call or argument.
Set wnd = CreateObject("UltraMon.Window") If wnd.GetForegroundWindow() = True Then Set sys = CreateObject("UltraMon.System") maxMon = sys.NumActiveMonitors For i = 0 To maxMon -1 Set curMon = sys.Monitors(i) ' This fails on an invalid argument If curMon.Enabled= True Then desktopWrkWdth = desktopWrkWdth + curMon.WorkWidth Next msg = "The desktop working width is " & desktopWrkWdth & "." ret = MsgBox(msg,vbOKOnly,"my UltraMon Script") End If
It also fails when using the Item property
Set curMon = sys.Monitors.Item(i)

I created a Select Case work around but it seems to be less than elegant.
Does anyone have a method to resolve this?

Thank You,
Patrick
Christian Studer   2008-11-24 09:24
You'll need to cast i to a long, looks like the loop counter is an integer:

Set curMon = sys.Monitors(CLng(i))

BTW, I would recommend changing the loop to use the Count property instead of NumActiveMonitors, for example you could have monitor 1 enabled, 2 disabled, and 3 enabled, and with NumActiveMonitors you would never get to monitor 3:

maxMon = sys.Monitors.Count

Christian Studer - www.realtimesoft.com
Patrick McKinley   2008-11-25 04:39
Thanks Christian. I knew it would be brain-dead simple and indicate my own awkwardness in coding. I'm glad it is that simple!
Thank You, Patrick

Thank You,
Patrick
Forums -> UltraMon™ SDK -> reference to a monitor in a collection

Post Reply