By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,483 Members | 3,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,483 IT Pros & Developers. It's quick & easy.

What's the best way to make a form return a value??

P: n/a
What's the best way to make a form return a value.... i want to try to avoid
using module variables for doing this...

Thanks.
Alex.
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
If you want to use a form like a dialog box, then you can use the showDialog
method, on the submit button you can me.hide and then on the following line
to the line calling the show method simply reference the forms members.


"Ale K." <_N******@AleK.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
What's the best way to make a form return a value.... i want to try to avoid using module variables for doing this...

Thanks.
Alex.

Nov 20 '05 #2

P: n/a
Property Get/Set statements on the form class would be better, IMO.
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:#c**************@TK2MSFTNGP09.phx.gbl...
If you want to use a form like a dialog box, then you can use the showDialog method, on the submit button you can me.hide and then on the following line to the line calling the show method simply reference the forms members.


"Ale K." <_N******@AleK.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
What's the best way to make a form return a value.... i want to try to

avoid
using module variables for doing this...

Thanks.
Alex.


Nov 20 '05 #3

P: n/a
Alex,
As OHM stated. You can use ShowDialog on your form.

In addition to manually calling me.Hide within the 'Submit' button, you can
have the form take care of it.

To do this you need to:
1. Set the Control.DialogResult value for your Submit/Ok button to
DialogResult.Ok
2. Set the Control.DialogResult value for your Cancel button to
DialogResult.Cancel
3. Set the Form.AcceptButton to your Submit/Ok button
4. Set the Form.CancelButton to your Cancel button

Then the form will take care of everything for you. Which ever button your
press will be the value returned from the ShowDialog call.

Dim dialog As MyDialog1
Select Case dialog.ShowDialog()
Case DialogResult.Ok
' the Submit/Ok button was pressed
Case DialogResult.Cancel
' the Submit/Ok button was pressed
' most of the time you just want to ignore cancel...
End Select
dialog.Dispose()

You can set other buttons to the other values of DialogResult and they will
be returned also. The Form's AcceptButton & CancelButton properties enable
Enter & Esc on the keyboard to be used for those buttons.

Then as OHM & Ed stated, your form class would expose properties to get the
values entered. You can use Properties to set any initial values. Similar to
how OpenFileDialog works.

Remember to call the Dispose method on your form, when you are done so that
it gets cleaned up.

Hope this helps
Jay

"Ale K." <_N******@AleK.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
What's the best way to make a form return a value.... i want to try to avoid using module variables for doing this...

Thanks.
Alex.

Nov 20 '05 #4

P: n/a
Nak
> Remember to call the Dispose method on your form, when you are done so
that
it gets cleaned up.


Hi Jay,

It's interesting you should say that as I have just been wondering as of
late, is it best to dispose of *every* idisposable object?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #5

P: n/a
Nak,
Yes, with exceptions ;-)

My understanding is if you call Form.Show, then Form.Close will call Dispose
for you, however if you call Form.ShowDialog then Form.Close will not call
Dispose for you. As when calling Form.ShowDialog you are normally wanting to
retrieve values from the form after the form is closed. Hence you need to
manually call Dispose...

Also I understand that when the form gets disposed it disposes of all its
children.

Currently that's the only actual exception that I know of.

Jay

"Nak" <a@a.com> wrote in message
news:Ot*************@TK2MSFTNGP11.phx.gbl...
Remember to call the Dispose method on your form, when you are done so that
it gets cleaned up.


Hi Jay,

It's interesting you should say that as I have just been wondering as

of late, is it best to dispose of *every* idisposable object?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ "No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

Nov 20 '05 #6

P: n/a
OK, but the logic still stands LMFAO

"Ed Crowley" <cu******@pacbell.net> wrote in message
news:uH**************@tk2msftngp13.phx.gbl...
Property Get/Set statements on the form class would be better, IMO.
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:#c**************@TK2MSFTNGP09.phx.gbl...
If you want to use a form like a dialog box, then you can use the

showDialog
method, on the submit button you can me.hide and then on the following

line
to the line calling the show method simply reference the forms members.


"Ale K." <_N******@AleK.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
What's the best way to make a form return a value.... i want to try to

avoid
using module variables for doing this...

Thanks.
Alex.



Nov 20 '05 #7

P: n/a
I think I'm going to Me.Dispose(). Its seems that I can never give enough
of an answer in the eyes of this group. Someone allways has do out do the
other one here.

I'm not taking away anything from the answers given here as they are
excellent if not a little verbose sometimes.

No disrespect to Jay as Jay allways give a very good answer.

But, maybe people like me should stand aside and let only the experts
answer.
Nov 20 '05 #8

P: n/a
OHM,
Then I need to:

GC.SupressFinalize(OHM)

Remember the ones that you consider "an expert" are learning also.
Personally one way to become an expert is to hang in there (here) and answer
questions, which is part of the reason I answer questions here. It exposes
me to aspects of the Framework that I may not normally look at.

I know I do not know every thing (read consider myself an expert), but you
did not hear that from me! :-)

Just a thought
Jay
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I think I'm going to Me.Dispose(). Its seems that I can never give enough of an answer in the eyes of this group. Someone allways has do out do the
other one here.

I'm not taking away anything from the answers given here as they are
excellent if not a little verbose sometimes.

No disrespect to Jay as Jay allways give a very good answer.

But, maybe people like me should stand aside and let only the experts
answer.

Nov 20 '05 #9

P: n/a
Cor
Ed,
Property Get/Set statements on the form class would be better, IMO.

What is the sence of that

dim frm as new "dialogform"
frm.showdialog(me)
x = frm.x
frm.close
frm.dispose

It exist mostly only one click from the user.

Why take more effort than necessary with that?

Cor
Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.