Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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.

Thanks.

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
0
halfondj
Asked:
halfondj
  • 3
  • 2
  • 2
1 Solution
 
ajexpertCommented:
Hi,
  Check if you are passsing v_frm as Form object and not a string
0
 
halfondjAuthor Commented:
To: ajexpert -- Please explain your answer.

Thanks.
0
 
EDDYKTCommented:
How do you call centerdlgbox and where do you call from?

Do you call like

CenterDlgBox Me
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
EDDYKTCommented:
If you use VB6, on your form_load event

set startupposition to 2 on design time will do the trick
0
 
ajexpertCommented:
Hi,
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)

0
 
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.
0
 
halfondjAuthor Commented:
BTW -- I was calling the routine like 'CenterDlgBox Me' where Me was the form (dialog box).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now