Centering a dialog box

I wanted to write a general routine that centers a dialog box.  I had the following routine, but when I ran the code through a code analyzer, it reported that the prototype was incorrect.  Is it and if so, please explain what's wrong.


Public Sub CenterDlgBox(ByVal v_frm As Form)
       On Error Resume Next

        v_frm.Top = (Screen.Height - v_frm.Height) / 2
        v_frm.Left = (Screen.Width - v_frm.Width) / 2
end sub
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  Check if you are passsing v_frm as Form object and not a string
halfondjAuthor Commented:
To: ajexpert -- Please explain your answer.

How do you call centerdlgbox and where do you call from?

Do you call like

CenterDlgBox Me
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

If you use VB6, on your form_load event

set startupposition to 2 on design time will do the trick

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dim v_Form as Form

set v_Form as MyForm

MyForm is the form name you have declared and call it as
Call CenterDlgBox(v_Form)

halfondjAuthor Commented:
To EDDYKT:  Thanks!  That's great and simple.  Why isn't that property more popular to use?  I've seen quite a bit of documentation re: the code snippet in my question.
halfondjAuthor Commented:
BTW -- I was calling the routine like 'CenterDlgBox Me' where Me was the form (dialog box).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.