Re: Passing to and back from Dialog

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





"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


.



Relevant Pages

  • Re: Passing to and back from Dialog
    ... I'd say the dialog box form should validate the data prior to unloading. ... you don't even unload it until the data's been validated. ... validation and the validation check fails. ... Use the intrinsic constants that VB provides. ...
    (microsoft.public.vb.general.discussion)
  • Variable Storage
    ... clicks this they are prompted with a MsgBox (vbYesNo). ... 'Yes' then I want to unload the form and then reload it again - ...
    (microsoft.public.excel.programming)
  • Re: Using Form_KeyPress to quit
    ... referencing the form or a control on the form. ... reload the form, run the Form_Load event again, and then continue. ... When you decide to unload you also need to use 'Exit Sub' and/or set a flag ... If you put a breakpoint in your Form_Load routine then when it happens the ...
    (microsoft.public.vb.general.discussion)
  • Re: b43 locks the machine when resuming after suspend to disk
    ... I can unload the module ... before suspending, ... reload it after resuming, same result; ... That starts to sound like some core problem -- bug in b43 does not ...
    (Linux-Kernel)
  • Re: it is possible to unload a class?
    ... Is it possible to reload a class in irb? ... >> I want to unload a library, a class or a gem, how can I do this, (or it ...
    (comp.lang.ruby)