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

Creating a form that retuns a value

P: n/a
The subject pretty much says it all. I need to create a form like the
msgbox that returns a value, how would I go about doing this?
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I am nto sure if there is a more standard way of doing this, but I would try
this approach...

Create your form, with all the functionality you need.

Add a public function to the form, that returns the value (or object) you
want.

Have the function contain the commands to show the form, and return whatever
value you need based on what the user does in the form.

After you return the value, close the form.

"Marco" <no****************@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
The subject pretty much says it all. I need to create a form like the
msgbox that returns a value, how would I go about doing this?

Nov 21 '05 #2

P: n/a
That's what I've been doing up until now but I was hopping that there was a
better way to do it. Oh well, stick with what works I guess. Thanks.
"Jim Underwood" <ja*************@fallonclinic.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
I am nto sure if there is a more standard way of doing this, but I would
try
this approach...

Create your form, with all the functionality you need.

Add a public function to the form, that returns the value (or object) you
want.

Have the function contain the commands to show the form, and return
whatever
value you need based on what the user does in the form.

After you return the value, close the form.

"Marco" <no****************@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
The subject pretty much says it all. I need to create a form like the
msgbox that returns a value, how would I go about doing this?


Nov 21 '05 #3

P: n/a
Don't give up yet. If there is a better way someone will post it soon.
Nov 21 '05 #4

P: n/a

Marco wrote:
That's what I've been doing up until now but I was hopping that there was a
better way to do it. Oh well, stick with what works I guess. Thanks.
Jim's solution isn't so bad :)

One nicety might be to make the method that's called a *Shared* method
(like MessageBox.Show is), so that the caller doesn't have to worry
about the details of instantiation.

this code is untried and might not even compile:

Class MyDialogBox
Inherits Form
'the form has a label control and a text box control on it
'and an ok button

Public Shared Function GetAnswer(byval Caption as string) as string
Dim box as new MyDialogBox()

box.Caption = Caption

Return box.Answer

'box will get tidied up automatically
End Function

Private _answer as string=""

Public Function Answer() As string
Me.ShowDialog

Return _answer
End Function

Public Property Caption as string
'(Code omitted: caption <-> label1.text)

private sub Textbox1_Changed('etc
_answer = Textbox1.Text
end sub

private sub Button1_Clicked('etc
Me.Hide
end sub
End Class

To use:

Dim TheAnswer As String = MyDialogBox.GetAnswer("What's the meaning of
life etc")



"Jim Underwood" <ja*************@fallonclinic.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
I am nto sure if there is a more standard way of doing this, but I would
try
this approach...

Create your form, with all the functionality you need.

Add a public function to the form, that returns the value (or object) you
want.

Have the function contain the commands to show the form, and return
whatever
value you need based on what the user does in the form.

After you return the value, close the form.

"Marco" <no****************@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
The subject pretty much says it all. I need to create a form like the
msgbox that returns a value, how would I go about doing this?



Nov 21 '05 #5

P: n/a
Making it shared is a good idea. One word of caution though...

If it is shared make absolutely certain that you are reinitializing any
variables or you will end up with the values from the last time the form was
accessed.

That said, a shared function will make things easier and is the way to go.
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...

Marco wrote:
That's what I've been doing up until now but I was hopping that there was a better way to do it. Oh well, stick with what works I guess. Thanks.


Jim's solution isn't so bad :)

One nicety might be to make the method that's called a *Shared* method
(like MessageBox.Show is), so that the caller doesn't have to worry
about the details of instantiation.

this code is untried and might not even compile:

Class MyDialogBox
Inherits Form
'the form has a label control and a text box control on it
'and an ok button

Public Shared Function GetAnswer(byval Caption as string) as string
Dim box as new MyDialogBox()

box.Caption = Caption

Return box.Answer

'box will get tidied up automatically
End Function

Private _answer as string=""

Public Function Answer() As string
Me.ShowDialog

Return _answer
End Function

Public Property Caption as string
'(Code omitted: caption <-> label1.text)

private sub Textbox1_Changed('etc
_answer = Textbox1.Text
end sub

private sub Button1_Clicked('etc
Me.Hide
end sub
End Class

To use:

Dim TheAnswer As String = MyDialogBox.GetAnswer("What's the meaning of
life etc")



"Jim Underwood" <ja*************@fallonclinic.com> wrote in message
news:O$**************@TK2MSFTNGP10.phx.gbl...
I am nto sure if there is a more standard way of doing this, but I wouldtry
this approach...

Create your form, with all the functionality you need.

Add a public function to the form, that returns the value (or object) you want.

Have the function contain the commands to show the form, and return
whatever
value you need based on what the user does in the form.

After you return the value, close the form.

"Marco" <no****************@hotmail.com> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
> The subject pretty much says it all. I need to create a form like the> msgbox that returns a value, how would I go about doing this?
>
>

Nov 21 '05 #6

P: n/a
"Marco" <no****************@hotmail.com> schrieb:
The subject pretty much says it all. I need to create a form like the
msgbox that returns a value, how would I go about doing this?


See:

<URL:http://groups.google.de/group/microsoft.public.de.german.entwickler.dotnet.vb/msg/255fcb93ea3510e5>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

P: n/a
In addition to using a shared method or just having a method available,
you can actually set and use the DialogResult property of any form,
whether it's modal or not.

As long as you are ok with using the DialogResult enumeration as the
returns, then you can do this.

In your form, just set your DialogResult like so... Me.DialogResult =
DialogResult.OK
Then in your other piece that's accessing this form...
if f.DialogResult = ... then...

If you need a specific value, you can also just set any of the
variables as needed. And just your instance of that form to grab the
necessary property you want to access.

Derek Woo

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.