473,776 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to pass values back from forms.

I basically am attempting to create a form with two checkboxes and want a 1, 2, or 3 to come back depending on the user choice to the calling form (like a message box, basically)

I didn't know if there was a way to pass it back other than throwing an error (which isn't an error) or raising an event (which would set a value outside of the module procedure)

Thanks

Nov 20 '05 #1
10 1270
Here's one way . . .

if you use showDialog method to show the form with the checkboxs on it, you can then continue with the code execution and extract the value selected on the form.

Dim frmCB as new formChkBx
'Puts the form in modal state so use has to take an action/ this should be to hide the form once the choise has been made
frmCB.ShowDialo g()

'get Values from form
'You can use the form like any other object so you can call its properties and methods.

'Then dispose of the form using the dispose method.

Regards - OHM

"Stephen Costanzo" <sx********@hot mail.com> wrote in message news:%2******** **********@TK2M SFTNGP12.phx.gb l...
I basically am attempting to create a form with two checkboxes and want a 1, 2, or 3 to come back depending on the user choice to the calling form (like a message box, basically)

I didn't know if there was a way to pass it back other than throwing an error (which isn't an error) or raising an event (which would set a value outside of the module procedure)

Thanks

Nov 20 '05 #2
* "Stephen Costanzo" <sx********@hot mail.com> scripsit:
I basically am attempting to create a form with two checkboxes and want a 1, 2, or 3 to come back depending on the user choice
to the calling form (like a message box, basically)


<http://www.google.com/groups?selm=u5Y 8SnOXDHA.1872%4 0TK2MSFTNGP12.p hx.gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Thanks,

That was going to be my next question - other than downloading 17K+ headers
how to search the archives, wasn't aware I could google it.
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bq******** *****@ID-208219.news.uni-berlin.de...
* "Stephen Costanzo" <sx********@hot mail.com> scripsit:
I basically am attempting to create a form with two checkboxes and want a 1, 2, or 3 to come back depending on the user choice to the calling form (like a message box, basically)

<http://www.google.com/groups?selm=u5Y 8SnOXDHA.1872%4 0TK2MSFTNGP12.p hx.gbl>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4
Referring to the code that you pointed out where:

Private Sub Button1_Click(. ..) ...
Dim f As New Form2()
If f.ShowDialog(Me ) = DialogResult.OK Then
MsgBox(f.Date.T oString())
Else
MsgBox("Cancell ed")
End If
End Sub

I have one point of confusion, on page 57 of Microsoft's Developing
Windows-based applications with Visual Basic .net (2nd ed) they indicate
that "you can call the Form.Close method to close the form and remove it
from memory. This method closes all resources contained within the form and
marks them for garbage collection. Once you have called form.close, you
cannot call form.show to make the form visible again because the resources
for the form are no longer available."

Therefore, in form 2 where:
Private Sub btnOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s _
) Handles btnOK.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

the close method is called. The confusion I have is that if I were expecting
that the resources from that form are unavailable that I would not be able
to get the result that was shown in the example. Granted GC happens at
irregular intervals, so there is a time when it is available, but is the
reason that one can consistently expect the example code to work because
button1 controls the memory space for the form variable and it isn't until
button1's variables leave scope that those variables are actually marked for
GC and are not available?

Thanks
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bq******** *****@ID-208219.news.uni-berlin.de...
* "Stephen Costanzo" <sx********@hot mail.com> scripsit:
I basically am attempting to create a form with two checkboxes and want a 1, 2, or 3 to come back depending on the user choice to the calling form (like a message box, basically)

<http://www.google.com/groups?selm=u5Y 8SnOXDHA.1872%4 0TK2MSFTNGP12.p hx.gbl>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #5
Hi Stephen,

Modal Forms (ShowDialog) do not get automatically Disposed on Close.
Modeless Forms (Show) get automatically Disposed on Close.
http://blogs.gotdotnet.com/rprabhu/p...8-4ff0-bd5b-d7
b41a0d0ebf

If you have any concern on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #6
Stephen,

Setting a form's DialogResult property will close the form (that is, HIDE it
from view) and return program control to the caller. In the caller you can
then query the form's properties where you can retrieve the values of
form-level variables marked PUBLIC or FRIEND. Once you are done with that,
you can then dispose of the form by calling it's dispose method.

Jeff
"Stephen Costanzo" <sx********@hot mail.com> wrote in message
news:OB******** *****@TK2MSFTNG P11.phx.gbl...
Referring to the code that you pointed out where:

Private Sub Button1_Click(. ..) ...
Dim f As New Form2()
If f.ShowDialog(Me ) = DialogResult.OK Then
MsgBox(f.Date.T oString())
Else
MsgBox("Cancell ed")
End If
End Sub

I have one point of confusion, on page 57 of Microsoft's Developing
Windows-based applications with Visual Basic .net (2nd ed) they indicate
that "you can call the Form.Close method to close the form and remove it
from memory. This method closes all resources contained within the form and marks them for garbage collection. Once you have called form.close, you
cannot call form.show to make the form visible again because the resources
for the form are no longer available."

Therefore, in form 2 where:
Private Sub btnOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s _
) Handles btnOK.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

the close method is called. The confusion I have is that if I were expecting that the resources from that form are unavailable that I would not be able
to get the result that was shown in the example. Granted GC happens at
irregular intervals, so there is a time when it is available, but is the
reason that one can consistently expect the example code to work because
button1 controls the memory space for the form variable and it isn't until
button1's variables leave scope that those variables are actually marked for GC and are not available?

Thanks
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bq******** *****@ID-208219.news.uni-berlin.de...
* "Stephen Costanzo" <sx********@hot mail.com> scripsit:
I basically am attempting to create a form with two checkboxes and
want
a 1, 2, or 3 to come back depending on the user choice to the calling form (like a message box, basically)


<http://www.google.com/groups?selm=u5Y 8SnOXDHA.1872%4 0TK2MSFTNGP12.p hx.gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Nov 20 '05 #7
Understood, I was just confused by the language from Microsoft as I
explicitly used the .close function in the button.

"Jeff Ptak" <jp***@REMOVE.N O-SPAM.stny.rr.co m> wrote in message
news:IN******** ************@tw ister.nyroc.rr. com...
Stephen,

Setting a form's DialogResult property will close the form (that is, HIDE it from view) and return program control to the caller. In the caller you can then query the form's properties where you can retrieve the values of
form-level variables marked PUBLIC or FRIEND. Once you are done with that, you can then dispose of the form by calling it's dispose method.

Jeff
"Stephen Costanzo" <sx********@hot mail.com> wrote in message
news:OB******** *****@TK2MSFTNG P11.phx.gbl...
Referring to the code that you pointed out where:

Private Sub Button1_Click(. ..) ...
Dim f As New Form2()
If f.ShowDialog(Me ) = DialogResult.OK Then
MsgBox(f.Date.T oString())
Else
MsgBox("Cancell ed")
End If
End Sub

I have one point of confusion, on page 57 of Microsoft's Developing
Windows-based applications with Visual Basic .net (2nd ed) they indicate
that "you can call the Form.Close method to close the form and remove it
from memory. This method closes all resources contained within the form

and
marks them for garbage collection. Once you have called form.close, you
cannot call form.show to make the form visible again because the resources
for the form are no longer available."

Therefore, in form 2 where:
Private Sub btnOK_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s _
) Handles btnOK.Click
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

the close method is called. The confusion I have is that if I were

expecting
that the resources from that form are unavailable that I would not be able to get the result that was shown in the example. Granted GC happens at
irregular intervals, so there is a time when it is available, but is the
reason that one can consistently expect the example code to work because
button1 controls the memory space for the form variable and it isn't until button1's variables leave scope that those variables are actually marked

for
GC and are not available?

Thanks
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bq******** *****@ID-208219.news.uni-berlin.de...
* "Stephen Costanzo" <sx********@hot mail.com> scripsit:
> I basically am attempting to create a form with two checkboxes and

want
a 1, 2, or 3 to come back depending on the user choice
> to the calling form (like a message box, basically)

<http://www.google.com/groups?selm=u5Y 8SnOXDHA.1872%4 0TK2MSFTNGP12.p hx.gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>



Nov 20 '05 #8
Hi Stephen,

Did the link in my last post answer your question?
If you have any conern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #9
Stephen,

One of the interesting things about clr garbage collection is that
when the sub shown below ends the f instance of the Form2 class is
disposed of along with all the items instantiated in the sub. So,
even though it is good practice to clean up after yourself, it isn't
really necessary in this case.

In some large projects we have worked on, we can't see a noticable
difference in code performance or resource usage either way.
"Stephen Costanzo" <sx********@hot mail.com> wrote in message news:<OB******* ******@TK2MSFTN GP11.phx.gbl>.. .
Referring to the code that you pointed out where:

Private Sub Button1_Click(. ..) ...
Dim f As New Form2()
If f.ShowDialog(Me ) = DialogResult.OK Then
MsgBox(f.Date.T oString())
Else
MsgBox("Cancell ed")
End If
End Sub

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2577
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through multiple records and want two values depending on the row they select. slaveform: x=selected
1
2412
by: JM | last post by:
Hello, Using Access 2000 queries, you can reference(pass) form values directly using syntax like Forms!frmPaint!txtColor. I want to do a pass through query to SQL Server 2000, but I don't know how to pass the form values to SQL server without resorting to VB code. These canned queries populate other elements of the form, and that's another reason I don't want to write additional code. These queries were originally set up merely...
7
21635
by: Zlatko Matiæ | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
2
2039
by: Chane | last post by:
hi i have doubt in how to pass values back to the called form. I have two forms, each having a textbox and a button control. First i'm run the first form and click the button, it creates object for second form and showed as modaless. And i entered some text in second form's textbox. While i clicked the seconds form's button the value in textbox of second form to be transfered to first form textbox. Thanx
8
3367
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
14
3608
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and click a button to bring up FormB which needs to display values entered in FormA. Thanks in advance.
13
3736
by: magickarle | last post by:
Hi, I got a pass-through query (that takes about 15 mins to process) I would like to integrate variables to it. IE: something simple: Select EmplID from empl_Lst where empl_lst.timestamp between !! And !! Not sure how to do so (should it be a query in Access or a macro) The connection would be ODBC.
12
11111
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
6
1700
by: =?Utf-8?B?Unlhbg==?= | last post by:
I am trying to pass a value from a texbox in Form1 to a textbox in Form2 using properties in VS2005 but it doesn't work; please help (project is attached). Code for Game Class: using System; using System.Collections.Generic; using System.Text;
0
10122
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
10061
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
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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
7471
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
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
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.