Solved

Centering a dialog box

Posted on 2003-12-08
7
187 Views
Last Modified: 2010-05-03
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
Comment
Question by:halfondj
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 9896080
Hi,
  Check if you are passsing v_frm as Form object and not a string
0
 

Author Comment

by:halfondj
ID: 9896125
To: ajexpert -- Please explain your answer.

Thanks.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9896196
How do you call centerdlgbox and where do you call from?

Do you call like

CenterDlgBox Me
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 9896206
If you use VB6, on your form_load event

set startupposition to 2 on design time will do the trick
0
 
LVL 14

Expert Comment

by:ajexpert
ID: 9896217
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
 

Author Comment

by:halfondj
ID: 9896306
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
 

Author Comment

by:halfondj
ID: 9896314
BTW -- I was calling the routine like 'CenterDlgBox Me' where Me was the form (dialog box).
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question