473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Creating a form that retuns a value

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
7 1262
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
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
Don't give up yet. If there is a better way someone will post it soon.
Nov 21 '05 #4

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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Don Stefani | last post by:
Hello, I have a form that I want to submit "onchange", OK I've got that working, but when the form submits, I want to pass along a value to a CGI script, as if that value was in a hidden form...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
20
by: Ash Phillips | last post by:
Hi Everyone, I have this program I wrote in VB6 for family use. It's a DVD Database just for me to keep track of them cause I have so many lol. In VB6, I could add items to the ListView in...
2
by: baret bonden | last post by:
Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes ..I' m able to display the chosen item on it's form...
2
by: deja | last post by:
Hello, I am creating an a to z list - basically a count of all results that start with the letter "A", "B", "C" .... and so on. I am pretty poor at SQL so I am sure some brains out there can...
6
by: Markus_989 | last post by:
I have a LOANS table that has a list of loan details for different borrowers. I have a main switchboard with a LOANSELECT combo box (that displays a list of borrower last names and loan numbers)....
1
by: OxfordConsult | last post by:
I have a form and it is to creat a 'link' between a project and a company. Creating a record form this table will simply create a record in a databse with the company ID and project ID. Project ID is...
4
by: .nLL | last post by:
yes <%=1/15%retuns 6.66666666666667E-02 anyone knows why or where i am wrong?
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.