?
Solved

Centering a dialog box

Posted on 2003-12-08
7
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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