473,804 Members | 3,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Rtn Varialbe from Second Form

I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form 2?

Ed

Jun 27 '08 #1
8 1024
Define a public/friend property (maybe readonly) on the second form and
access it from the first form.
--
Terry
"Ed Bitzer" wrote:
I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form 2?

Ed

Jun 27 '08 #2
Thanks Terry.... I can pass information over to form2 using a Friend
Write Only property but I am over my head trying to grab that same
property after changing it and passing it back.

Ed

"Terry" <Te****@nospam. nospamwrote in message
news:7B******** *************** ***********@mic rosoft.com...
Define a public/friend property (maybe readonly) on the second form
and
access it from the first form.
--
Terry
"Ed Bitzer" wrote:
>I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form
2?

Ed


Jun 27 '08 #3
well if you want to both set it before hand and read it afterwards, then
don't make it write only.

form2.someprope rty = "Boo"
form2.showdialo g
thevalue = form2.someprope rty

--
Terry
"Ed Bitzer" wrote:
Thanks Terry.... I can pass information over to form2 using a Friend
Write Only property but I am over my head trying to grab that same
property after changing it and passing it back.

Ed

"Terry" <Te****@nospam. nospamwrote in message
news:7B******** *************** ***********@mic rosoft.com...
Define a public/friend property (maybe readonly) on the second form
and
access it from the first form.
--
Terry
"Ed Bitzer" wrote:
I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form
2?

Ed



Jun 27 '08 #4
"Ed Bitzer" <ed******@yahoo .comschrieb:
>I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form 2?
Sample:

\\\
Public Class Form2
Inherits System.Windows. Forms.Form

#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
InitializeCompo nent()
End Sub
Protected Overloads Overrides Sub Dispose( _
ByVal disposing As Boolean _
)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

Private components As System.Componen tModel.IContain er

Friend WithEvents btnCancel As System.Windows. Forms.Button
Friend WithEvents btnOK As System.Windows. Forms.Button
Friend WithEvents DateTimePicker1 As System.Windows. Forms.DateTimeP icker

<System.Diagnos tics.DebuggerSt epThrough()_
Private Sub InitializeCompo nent()
Me.btnCancel = New System.Windows. Forms.Button()
Me.btnOK = New System.Windows. Forms.Button()
Me.DateTimePick er1 = New System.Windows. Forms.DateTimeP icker()
Me.SuspendLayou t()
'
'btnCancel
'
Me.btnCancel.Di alogResult = System.Windows. Forms.DialogRes ult.Cancel
Me.btnCancel.Fl atStyle = System.Windows. Forms.FlatStyle .System
Me.btnCancel.Lo cation = New System.Drawing. Point(176, 144)
Me.btnCancel.Na me = "btnCancel"
Me.btnCancel.Si ze = New System.Drawing. Size(80, 24)
Me.btnCancel.Ta bIndex = 0
Me.btnCancel.Te xt = "Cancel"
'
'btnOK
'
Me.btnOK.FlatSt yle = System.Windows. Forms.FlatStyle .System
Me.btnOK.Locati on = New System.Drawing. Point(88, 144)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing. Size(80, 24)
Me.btnOK.TabInd ex = 1
Me.btnOK.Text = "OK"
'
'DateTimePicker 1
'
Me.DateTimePick er1.Location = New System.Drawing. Point(16, 24)
Me.DateTimePick er1.Name = "DateTimePicker 1"
Me.DateTimePick er1.Size = New System.Drawing. Size(240, 20)
Me.DateTimePick er1.TabIndex = 2
'
'Form2
'
Me.AcceptButton = Me.btnOK
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing. Size(274, 184)
Me.Controls.Add Range(New System.Windows. Forms.Control() {Me.DateTimePic ker1,
Me.btnOK, Me.btnCancel})
Me.FormBorderSt yle = System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form2"
Me.ShowInTaskba r = False
Me.Text = "Select date"
Me.ResumeLayout (False)
End Sub
#End Region

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

Private Sub btnCancel_Click ( _
ByVal sender As System.Object, _
ByVal e As System.EventArg s _
) Handles btnCancel.Click
Me.DialogResult = DialogResult.Ca ncel
Me.Close()
End Sub

Public Property [Date]() As Date
Get
Return Me.DateTimePick er1.Value
End Get
Set(ByVal Value As Date)
Me.DateTimePick er1.Value = Value
End Set
End Property
End Class
///

Call:

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

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

Jun 27 '08 #5
Terry and Herfried,

I have spent about about four hours trying to digest and make work
code that is my best interpretation of your responses, but please
forgive, I am going to bed (75 years need extra sleep) and will work
again tomorrow and the holiday. If I fail it is not your fault and I
do appreciate.

Ed

"Ed Bitzer" <ed******@yahoo .comwrote in message
news:ua******** ******@TK2MSFTN GP05.phx.gbl...
>I am trying to avoid global variables and take advantage of OOP and
now understand how to pass a variable to another form using a
constructor. But how to I return that variable if changed on Form
2?

Ed

Jun 27 '08 #6
Terry and Herfried,

I got it...spent some time learning how to use OOP using the videos on
the Express website and of course my Form2 is just another class. I
simply created Properties on Form2 and with Methods can modify and of
course use these back on Form1. I have made a big step forward and
will now avoid the use of Modules (and now not sure its purpose) and
definitely global variables.

Herfied's example is much more involved and although I can get Form2
to compile and have not figures out what information belongs on Form1
which of course I can display with fmr2.showDialog () after creating
with new.

Ed

Jun 27 '08 #7
Sounds like you made a leap forward. Yes, form2 is just another class that
can expose properties like any other class.
--
Terry
"Ed Bitzer" wrote:
Terry and Herfried,

I got it...spent some time learning how to use OOP using the videos on
the Express website and of course my Form2 is just another class. I
simply created Properties on Form2 and with Methods can modify and of
course use these back on Form1. I have made a big step forward and
will now avoid the use of Modules (and now not sure its purpose) and
definitely global variables.

Herfied's example is much more involved and although I can get Form2
to compile and have not figures out what information belongs on Form1
which of course I can display with fmr2.showDialog () after creating
with new.

Ed

Jun 27 '08 #8
Terry,

Hope you understand that this is a great hobby for a guy now retired
15 years. In the early days I had to program simply because software
just was not available for calculations and data manipulation and I
worked for a small manufacturing company that had no computer staff -
so I have programmed in RPGII, Cobol, all the MS Basics, Turbo Pascal
and then VB and now VB.net. So not being a full time job I now enjoy
as a hobby. Guys like you and Herfried sure make my day because I
have no staff with which to confer - in fact in my community I know of
know one else that even would consider programming.

Now sharing my programs with friends and families is a problem with
VB8. VB5 had a nice install program. Express's install provides no
options, such as where it will place the program, and sure stuffs it
in an obscure folder under Documents and Settings. I wrote one that
has a spell checker which uses Word and I have yet to figure out how
to send the necessary files so that they don't have to bury them. From
what I read, purchasing an upgrade might have a more conventional
install program. But it does keep me out of trouble.

Ed

"Terry" <Te****@nospam. nospamwrote in message
news:17******** *************** ***********@mic rosoft.com...
Sounds like you made a leap forward. Yes, form2 is just another
class that
can expose properties like any other class.
--
Terry

Jun 27 '08 #9

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

Similar topics

5
4264
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form: <form method="post" action="<?php $server?>">
5
5103
by: TG | last post by:
Conditions: Register globals is set to on. Parse html as php is set to on. I have two forms OrderTest1 and OrderTest2 and need to be able to validate the data from OrderTest1 before passing to OrderTest2. The first block of code below is the first form. This form calls itself and does perform the validations correctly as I want. However, once the header redirect to OrderTest2.htm is performed after the isset($POST)) evaluates as true...
1
3040
by: MP | last post by:
I have a main form that has a subform which also has a subform: the main form is the first subform is the second subform is When I click on the button »AddNewSubSubRecord« (add a new record in the second subform , the code generates the message: Can't find the field »POG-03 Work Subform« reffrred to in your expression.
2
5053
by: bryhhh | last post by:
I have am still learning C#, so please bear with me. I have an application that needs to open a second form, but I need the second form to process message loops, whilst the original form also continues to process message loops. At the moment, my second form contains this code (and more irrelevant code not listed) public class SecondForm : System.Windows.Forms.Form
3
1534
by: MajorTom | last post by:
Hello everybody, I need help on how to use the same datase in two different form, this is the scenario: at the first form I load a big dataset (ds1) for short, but I not want to load it again at the second form at some point I use a second form Form f = new FormX(); f.ShowDialog();
9
1964
by: twnety0ne | last post by:
Hey guys, I have multiple forms in my windows app, and in my startup form i am doing the following in order to navigate to a different form: Dim myform as New frmsecondform frmsecondform=mynamespace.originalsecondformname myform.show As soon as I try to run the application, the main form shows up, I try to click the button to navigate to a different form but it just closes., without
3
16394
by: Brett Romero | last post by:
My application start like this: frmMaster MainForm = new frmMaster(); System.Windows.Forms.Application.Run(MainForm); The flow is that MainForm shows then a SecondForm shows after the user does something. This is an MDI app so SecondForm needs to always be inside MainForm. There are times I need to automatically load the app and display second form. I'm not sure how that is done. If I do:
5
2069
by: huseyin | last post by:
Hello, I have two forms written mainly in php. Here how it functions currently: - First form has two submit buttons. - First submit button is a search button that submits a value of an input field that activates a database query and get the result - I control the length of the entered text with Java Script in the input field and activate the query without clicking the search button when a certain length is achieved - second submit...
6
1298
by: John | last post by:
Hi Can I run a from in one project from a second project, both projects being in the same solution? Thanks Regards
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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
10332
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
10320
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
9150
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...
0
6853
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();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
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
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.