Solved

Centering a dialog box

Posted on 2003-12-08
7
184 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
Comment Utility
Hi,
  Check if you are passsing v_frm as Form object and not a string
0
 

Author Comment

by:halfondj
Comment Utility
To: ajexpert -- Please explain your answer.

Thanks.
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
How do you call centerdlgbox and where do you call from?

Do you call like

CenterDlgBox Me
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
BTW -- I was calling the routine like 'CenterDlgBox Me' where Me was the form (dialog box).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now