Re: Passing to and back from Dialog
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sat, 14 Nov 2009 21:44:10 -0500
"Webbiz" <nospam@xxxxxxxxxxxxxxxx> wrote in message news:c3ksf51ni74289qiijpkrvf64eccmk2e51@xxxxxxxxxx
When a user double-clicks a text box, a dialog box is to open and the
info from that text box sent over so that the dialog box would have
some initial data to display.
The user than can change that information from within the dialog box.
When the user clicks on the OK button, that information needs to be
returned to the same routine (the textbox doubleclick) that called the
dialog box.
To send data over, I thought to use the .Tag property of the dialog
box.
Dialog.Tag = dMyDateInfo
Dialog.Show 1, Me
The dialog's Activate method deals with the dMyDateInfo sent over.
However, when I wish to send the data back and close the dialog, so as
to test the validity of the info if the user entered a change, the
.Tag cannot be used. This is because the dialog is unloaded.
Now, I know I can create a Global variable and set it to the return
value. But I would like to find ways to minimize the number of Global
variables being added to the project. Once that data is sent back, I
have no other use for such a variable.
What is the suggested way to do this?
There really should be no need for a global variable at all.
I'd say the dialog box form should validate the data prior to unloading. That way, you don't even unload it until the data's been validated.
But there are other ways to approach this. For example, instead of unloading the dialog box, hide it. That way you can make it visible again if the calling procedure (the proc that shows the dialog) has to do the validation and the validation check fails. Unload the form AFTER the validation check succeeds.
Another option would be to create a Public property in the dialog box form. You can unload the form and still access that property without causing the form to reload. Only a form's intrinsic properties cause the form to reload when referenced. Properties you add don't cause the form to reload. They are cleared by setting the form's object variable to Nothing (or writing a method to clear or explicitly setting the property to a default value).
A tip. Don't use "magic numbers". In your code in which you show the dialog, instead of using
Dialog.Show 1, Me
you should have:
Dialog.Show vbModal, Me
Use the intrinsic constants that VB provides. It makes your code MUCH more concise and therefore easier to read and understand and maintain.
--
Mike
.
- Follow-Ups:
- Re: Passing to and back from Dialog
- From: Webbiz
- Re: Passing to and back from Dialog
- References:
- Passing to and back from Dialog
- From: Webbiz
- Passing to and back from Dialog
- Prev by Date: Re: Need for thumbnails
- Next by Date: Re: Preventing an app from being run remotely
- Previous by thread: Re: Passing to and back from Dialog
- Next by thread: Re: Passing to and back from Dialog
- Index(es):
Relevant Pages
|