473,385 Members | 1,641 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,385 software developers and data experts.

Passing Value Back (forms)

My goal is to open Form2 from Form1 and have Form2 pass back an integer to
Form 1.

In VB, this is rather simple:

Form 1 (vanilla form with a button):
Dim WithEvents x As Form2
Dim i As Integer

Sub form2Event(ByVal num As Integer) Handles x.RouteNumber
i = num
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = New Form2
x.ShowDialog()
MessageBox.Show(i.ToString)
End Sub

Form 2 (vanilla form with a button)

Public Event RouteNumber(ByVal num As Integer)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent RouteNumber(5)
Me.Close()
End Sub

When I look to do this simple function in C#, it appears (from the Event
Sample in the help) to involve a whole lot of coding, including creating
classes to handle the event etc. Am I just spoiled by VB.NET and its event
handling or am I misreading the C# documentation from the help files.

Thanks in advance.
Nov 17 '05 #1
2 3464
Why not just have the Route Number be a public property of Form2 that can be
read after the call to ShowDialog?

Form 2 (vanilla form with a button)

Public RouteNumber as Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RouteNumber = 5
Me.Close()
End Sub

Form1

Dim x As Form2
Dim i As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = New Form2
x.ShowDialog()
MessageBox.Show(x.RoutNumber.ToString)
End Sub


"Stephen Costanzo" <sx********@hotmail.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
My goal is to open Form2 from Form1 and have Form2 pass back an integer to
Form 1.

In VB, this is rather simple:

Form 1 (vanilla form with a button):
Dim WithEvents x As Form2
Dim i As Integer

Sub form2Event(ByVal num As Integer) Handles x.RouteNumber
i = num
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = New Form2
x.ShowDialog()
MessageBox.Show(i.ToString)
End Sub

Form 2 (vanilla form with a button)

Public Event RouteNumber(ByVal num As Integer)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent RouteNumber(5)
Me.Close()
End Sub

When I look to do this simple function in C#, it appears (from the Event
Sample in the help) to involve a whole lot of coding, including creating
classes to handle the event etc. Am I just spoiled by VB.NET and its event
handling or am I misreading the C# documentation from the help files.

Thanks in advance.

Nov 17 '05 #2
As long as that doesn't violate some principle in coding, that's fine. I
wasn't sure if doing that violated some OO principle.

Side Note: Is there a site that lists the 'dos and don'ts of OO'? I know
that global variables are a "don't" but wouldn't know if exposing the
property as Teddb specified is ok - seems like it would be as a form is
simply a class.

Thanks

"Tedb" <an**@anon.com> wrote in message
news:uJ*************@TK2MSFTNGP15.phx.gbl...
Why not just have the Route Number be a public property of Form2 that can be read after the call to ShowDialog?

Form 2 (vanilla form with a button)

Public RouteNumber as Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RouteNumber = 5
Me.Close()
End Sub

Form1

Dim x As Form2
Dim i As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = New Form2
x.ShowDialog()
MessageBox.Show(x.RoutNumber.ToString)
End Sub


"Stephen Costanzo" <sx********@hotmail.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
My goal is to open Form2 from Form1 and have Form2 pass back an integer to Form 1.

In VB, this is rather simple:

Form 1 (vanilla form with a button):
Dim WithEvents x As Form2
Dim i As Integer

Sub form2Event(ByVal num As Integer) Handles x.RouteNumber
i = num
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
x = New Form2
x.ShowDialog()
MessageBox.Show(i.ToString)
End Sub

Form 2 (vanilla form with a button)

Public Event RouteNumber(ByVal num As Integer)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RaiseEvent RouteNumber(5)
Me.Close()
End Sub

When I look to do this simple function in C#, it appears (from the Event
Sample in the help) to involve a whole lot of coding, including creating
classes to handle the event etc. Am I just spoiled by VB.NET and its event handling or am I misreading the C# documentation from the help files.

Thanks in advance.


Nov 17 '05 #3

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

Similar topics

8
by: Alex Vinokur | last post by:
Various forms of argument passing ================================= C/C++ Performance Tests ======================= Using C/C++ Program Perfometer...
2
by: Ed | last post by:
I need to know how to pass variables because I want to use the same function to varify multiple data imput boxes. Please tell me what's wrong with this code. <head> <script...
9
by: Max | last post by:
I'm new with Javascript and can't seem to figure out what I'm doing wrong here as I'm not able to pass a simple variable to a function. In the head of doc I have: <script...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
0
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
5
by: manningfan | last post by:
I have a single form that I want to make as generic as possible. The form contains a Calendar control. Using OpenArgs I pass values from the form that's calling the calendar, and the field the...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.