Screen Dimensions in Visual Basic

Monkeyanator picture Monkeyanator · Oct 21, 2011 · Viewed 16.3k times · Source

How can you access the dimensions of the screen in Visual Basic? I have looked online and it says to use Screen.width and Screen.length, but it doesn't recognize those properties... any tips?

Answer

Boann picture Boann · Oct 21, 2011

In VB you can use Screen.Width and Screen.Height. They're not in VBA but you can use an API call instead. Add these declarations:

Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal index As Long) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Then use like so:

MsgBox GetSystemMetrics(SM_CXSCREEN) & "x" & GetSystemMetrics(SM_CYSCREEN)