473,769 Members | 7,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1277
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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP15.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$******** ******@TK2MSFTN GP10.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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP15.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_Change d('etc
_answer = Textbox1.Text
end sub

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

To use:

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



"Jim Underwood" <ja************ *@fallonclinic. com> wrote in message
news:O$******** ******@TK2MSFTN GP10.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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP15.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*******@hotm ail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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_Change d('etc
_answer = Textbox1.Text
end sub

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

To use:

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



"Jim Underwood" <ja************ *@fallonclinic. com> wrote in message
news:O$******** ******@TK2MSFTN GP10.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.co m> wrote in message
news:O$******** ******@TK2MSFTN GP15.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.co m> 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.d e/group/microsoft.publi c.de.german.ent wickler.dotnet. vb/msg/255fcb93ea3510e 5>

--
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
1982
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 element. BUT, I don't want that value to be in the actual HTML form, I want it to be created in my submit function. For instance:
6
3252
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." exception. The problem is that this exception isn't raised somewhere in a method, so it just shows up, and it causes the application to shut down. Is there anyway how to catch this kinds of exceptions? Can I put somewhere a
20
6676
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 'frmMain' from 'frmAdd' with the following code: Private Function AddEntry(Title As String, Rating As String, Genre As String, OnLoan As Boolean, ToWho As String)
2
4881
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 in a textbox and I'm able to pass other variables to the 2nd form, but not the data I want . I should add this is a smartdeviceapplication(if that matters; not sure) Here's most of the test code .
2
2495
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 do better than I have here. What I have is working, I just want to make sure that it is optomized.
6
3535
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). I'd like to be able to have a user click on the say, RECEIVE PAYMENT button that will open the payments form. This form should open to the loan that was selected from the LOANSELECT box. This form also has a box on it to switch to different...
1
2022
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 selected form a drop down bax and Company ID is selected from a combo box. I am trying to create a script that if you click exit form, and one or the other, or both of the fields have a selection it will bring up message box and inform the user of...
4
1606
by: .nLL | last post by:
yes <%=1/15%retuns 6.66666666666667E-02 anyone knows why or where i am wrong?
5
3558
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 createNewFile($name,$mail,$subject,$comments,$count,$date,$other="",$up="0") { global $settings; $header=implode('',file('header.txt')); $footer=implode('',file('footer.txt')); $content=' <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.