Solved

Simulate a message box, center commondialog box

Posted on 1998-09-30
17
374 Views
Last Modified: 2010-04-30
Dear Experts,
    I am tryiny to create something just like a message. Except that it contains a few checkboxes to enable people to select differently. I am trying to use a form to do that.
    However I find that for a message box provided by VB, after you click OK, the program execution returns to the line immediately after the message box. The form I created to simulate the message box cannot do that. "Goto" only works within a procedure thus it is not useful.
     How can I simulate using a form that will return execution to the point(in the original form) where it was originally called and pass back a variable (of a user created type) to the original form?

     status=myOwnMessageBox()

     The second question is how to center the file open commondialog box?

     Thanks in advance.

Cheers,
0
Comment
Question by:happydanny
  • 5
  • 4
  • 4
  • +3
17 Comments
 
LVL 1

Expert Comment

by:kacklehorn
Comment Utility
You need to make your form modal. i.e frmMessage.Show vbmodal,me.

This will not execute any more lines of code until the user hit OK or closes the form.
0
 
LVL 1

Expert Comment

by:kacklehorn
Comment Utility
As far as centering the commondialog box, if you look in the help for it, it says you can't do it. However I'm sure that there is an API that will allow this. I'll check on it for you.
0
 
LVL 2

Expert Comment

by:polygon
Comment Utility
you may declare a public variable of type Boolean, say MyBool, then run the code like

MyMsgBox(......)
do
loop until MyBool
..

you will have to declare another variable to store the info that should have been retuned as this method does not provide a retun value. You will set MyBool True when you hide you MsgBox form.
0
 

Author Comment

by:happydanny
Comment Utility
Dear Polygon,
    I am afraid the do loop will not even be executed. After the point where another form is called (the simulated message box), the control does not return to the same procedure that calls it.

Regards,
Dan
0
 
LVL 2

Expert Comment

by:Grdv
Comment Utility
In answer to your first question I must agree kacklehorn and then in reply to the other question... if you declare the commondialogcontrol through api, you can use set parent with .hInstance as child to get the commondialogs topleft aligned together with the topleft of the parent...from that you can make it centered...
 I don't know if this is possible with a usual commondialog...

Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As  Long, ByVal hWndNewParent As Long) As Long
0
 

Author Comment

by:happydanny
Comment Utility
Dear Polygon,

    You are right. I don't know what got into me the first time I tried it. But your solution works!
    Please propose a solution again so I can pass you the points. Not that you will need them, since you know so much of VB you won't need help anyway. :)
    Thanks!

Regards,
Dan

0
 
LVL 2

Expert Comment

by:Grdv
Comment Utility
Just one question happydanny, what was wrong with the suggestion from kacklehorn??
and btw, that doesn't take that amout of comp power that the other method do...
I vbModal window works exactly the same as a msgbox that itself is a MODALFRAME object...
but it's up to you...

Gustav
0
 

Expert Comment

by:ZoroZor
Comment Utility
The right answer is from polygon.

It's not possible to wait for an input issued from an object event. In POO, many events can occur silmutanously. If you want to wait for a data modified in an other sub ... the only way is to make a do while loop in the first sub as Polygon said.
0
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

 
LVL 2

Expert Comment

by:Grdv
Comment Utility
ZoroZor:
first of all I don't agree with you, but it doesn't matter...
you can try it yourself...make a project with 2 different forms (frm1,frm2)
in frm1 (which is the mainform,startupform) print in the load event
Private sub form_load()
  frm2.show vbModal, Me
  MsgBox "here you see", , "test"
end sub
you will see that the program show's the frm2 dialog and wait's until it's closed to continue with the next line of code... which displays a messagebox...
if you instead wrote
Private sub form_load()
  frm2.show
  MsgBox "here you see", , "test"
end sub
then both of the boxes would appear as the frm2 wouldn't be a MODALFRAME of frm1 and the code would continue to execute....
and secondly, if you think polygon was right, you should have sent that as a comment and not as an answer... if nothing else your preventing polygon from getting his points??
even though that answer is incorrect...
but it's all up to happydanny, who he wants to give the points to...
as far as I'm concerned noone except me has even tried to come up with a solution for the center commondialog problem... but well, well...
so, what should be the most fair thing to do is for happydanny, to try my thing and then tell here what was wrong and reject ZoroZor's answer and let somebody answer to both his questions...
0
 

Author Comment

by:happydanny
Comment Utility
Dear All,
    Polygon method works but I think Grdv and kacklehorn method is much more efficient. I initially rejected his kacklehorn's answer because I mistyped(in fact I knew about the modal thing before kacklehorn mentioned it but implement it wrongly)

    form.show modal, me
 
    This did not give me an error but it did not go into modal mode. Since Grdv is so insistant on his claims I took a second look and realised my mistaked. It should be "vbModal".

    Sorry I can't pass you the points ZorZor. If I have more points I would like to pass you some for making the effort to help. But I am kinda low now so....sorry.

    Thanks to Grdv and kacklehorn for proposing the right solution. I will hand the points to either one of them which register a proposed answer first.

    I will have to reject ZorZor's answer to enable them to do that. Sorry about that.

Regards,
Dan
0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
You need to Set the form As a Modal Form.
Also.. in the Declare a Form level Variable.
Public Answer as Integer

In CmdCancel Button..
   say Answer = -1
Then in your Form Unload Event..
   say Answer = BoxOne * -1 + Box2 * -2
This Sets that Variable to an answer.

In your Form that calls this maybe do this

MyMessage.show vbmodal
'This line wont get hit until the user gets off that other form

then do this..
Select case MyMessage.Answer
case -1
  call DothisBecauseUserHitCancel
case 0
  Call DoThisBecasueUserSelectNothing
case 1
  call DoThisBecasueUserSelectedTheFirstBox
case 2
  call DoThisBecasueUserSelectedTheSecondBox
case 3
  call DoThisBecasueUserSelectedBothboxes
end select


maybe here is an example
'0- = cancel
'1 = Box One selected
'2 = Box Two Selected
'3 = Both One and Two Selected

0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
and i Should Get ALL the points.. becasue I answered them ALL  (you wanted a return Value) instead of arguing over modality.
0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
and i Should Get ALL the points.. becasue I answered them ALL  (you wanted a return Value) instead of arguing over modality.
0
 

Author Comment

by:happydanny
Comment Utility
Dear AnswerMan,
     There is no merit in showing me how to use a Global variable. Others please kindly do not propose an answer as I am waiting for Grdv or kacklehorn to collect their points.
     Thanks!

Cheers,
Dan
0
 
LVL 2

Accepted Solution

by:
Grdv earned 50 total points
Comment Utility
What you need is as I said to launch the frame in vbModal-mode... that's all there is to it.
just like this:
Form1.Show vbModal, Me.

thanks for understanding...

// Gustav
0
 

Author Comment

by:happydanny
Comment Utility
Dear Grdv,

    Don't worry, you already told me the answer long ago. I am not asking you for another answer, just asking you to put a line in the proposed answer to collect the points that's all. Here's the points you well deserved!
    Thanks for the help man.

Cheers,
Dan
0
 
LVL 3

Expert Comment

by:TheAnswerMan
Comment Utility
you puss.. Thats not a global variable..
ITs a Public Variable that ges created when you create a
New Instance of the form you want.  If you create 5 forms.. you get 5 variables.  try that with your "global Variable"

Modality was only half the problem.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now