By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,694 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,694 IT Pros & Developers. It's quick & easy.

How do I call a method of another from

P: n/a
Hello,
I have a Customer form say A to enter/update customer details. In the Form
A I have a button which opens another form say B.

In the Form B, I am providing user with a option to search Customer from the
database depending on various search criteria.

On matching the criteria, list of Customer is displayed in the datagrid.
Selecting a particular row and click on OK button will do the following

1. Close the Form B

2. Load the information of the selected customer in the form A.
I am having problem in loading the information in Form A.

Can anybody help me in solving this issue.
Partha
Nov 21 '05 #1
Share this Question
Share on Google+
33 Replies


P: n/a

"Partha Protim Roy" <pa****@capoint.com> wrote
Hello, I have a Customer form say A to enter/update customer details. In the Form
A I have a button which opens another form say B.

In the Form B, I am providing user with a option to search Customer from the
database depending on various search criteria.

On matching the criteria, list of Customer is displayed in the datagrid.
Selecting a particular row and click on OK button will do the following

1. Close the Form B

2. Load the information of the selected customer in the form A.
I am having problem in loading the information in Form A.

I am assuming your problem is in the transfer from B to A?

Give A a method to load and display the details based on a
Customer name " A.LoadDetails(CustomerName)

Give B a public function to return a string that will be your
users selection; B.GetCustomerName()

From A's button, create a form B and ask it for the name:

Dim FormB As New FormB
Dim name As String

name = FormB.GetCustomerName()
FormB = Nothing
If name.Length > 0 then LoadDetails(name)
In FormB's (Public) GetCustomerName function, load
the customer list, and show the dialog.

LoadCustomerList
Me.ShowDialog
Return UserSelection

UserSelection is a module level String variable. If the user
selects a name and hits OK, then set that UserSelection string
to the selected name, and close the form. If the user hits Cancel,
then just close the form.

The value of UserSelection will be assigned to the name variable
back in FormA after the form closes, and as shown, if there is
something in it, then use it, and if not, the user opted to cancel.

HTH
LFS

Nov 21 '05 #2

P: n/a
Hello Larry,

Thanks.

I tried the way you have suggested but it is not happening.

It could be the reason that my Form B is modal.

Partha
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

"Partha Protim Roy" <pa****@capoint.com> wrote
Hello,

I have a Customer form say A to enter/update customer details. In the Form A I have a button which opens another form say B.

In the Form B, I am providing user with a option to search Customer from the database depending on various search criteria.

On matching the criteria, list of Customer is displayed in the datagrid.
Selecting a particular row and click on OK button will do the following

1. Close the Form B

2. Load the information of the selected customer in the form A.
I am having problem in loading the information in Form A.

I am assuming your problem is in the transfer from B to A?

Give A a method to load and display the details based on a
Customer name " A.LoadDetails(CustomerName)

Give B a public function to return a string that will be your
users selection; B.GetCustomerName()

From A's button, create a form B and ask it for the name:

Dim FormB As New FormB
Dim name As String

name = FormB.GetCustomerName()
FormB = Nothing
If name.Length > 0 then LoadDetails(name)
In FormB's (Public) GetCustomerName function, load
the customer list, and show the dialog.

LoadCustomerList
Me.ShowDialog
Return UserSelection

UserSelection is a module level String variable. If the user
selects a name and hits OK, then set that UserSelection string
to the selected name, and close the form. If the user hits Cancel,
then just close the form.

The value of UserSelection will be assigned to the name variable
back in FormA after the form closes, and as shown, if there is
something in it, then use it, and if not, the user opted to cancel.

HTH
LFS

Nov 21 '05 #3

P: n/a
Overload the constructor in form B

Private ParentForm As Form

Public Sub New( ByRef Parent As Form )

ParentForm = Parent

.. . . .

Now you can update members of the Parent Form with search results etc
ParentForm.MyProperty =

And then Close Form

Me.Close

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Partha Protim Roy" <pa****@capoint.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
Hello Larry,

Thanks.

I tried the way you have suggested but it is not happening.

It could be the reason that my Form B is modal.

Partha
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

"Partha Protim Roy" <pa****@capoint.com> wrote
Hello,
I have a Customer form say A to enter/update customer details. In the Form A I have a button which opens another form say B.

In the Form B, I am providing user with a option to search Customer from the
database depending on various search criteria.

On matching the criteria, list of Customer is displayed in the

datagrid. Selecting a particular row and click on OK button will do the following
1. Close the Form B

2. Load the information of the selected customer in the form A.
I am having problem in loading the information in Form A.

I am assuming your problem is in the transfer from B to A?

Give A a method to load and display the details based on a
Customer name " A.LoadDetails(CustomerName)

Give B a public function to return a string that will be your
users selection; B.GetCustomerName()

From A's button, create a form B and ask it for the name:

Dim FormB As New FormB
Dim name As String

name = FormB.GetCustomerName()
FormB = Nothing
If name.Length > 0 then LoadDetails(name)
In FormB's (Public) GetCustomerName function, load
the customer list, and show the dialog.

LoadCustomerList
Me.ShowDialog
Return UserSelection

UserSelection is a module level String variable. If the user
selects a name and hits OK, then set that UserSelection string
to the selected name, and close the form. If the user hits Cancel,
then just close the form.

The value of UserSelection will be assigned to the name variable
back in FormA after the form closes, and as shown, if there is
something in it, then use it, and if not, the user opted to cancel.

HTH
LFS


Nov 21 '05 #4

P: n/a
I could not get you .

Please, write in details.

Thanks
Partha
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
Overload the constructor in form B

Private ParentForm As Form

Public Sub New( ByRef Parent As Form )

ParentForm = Parent

. . . .

Now you can update members of the Parent Form with search results etc
ParentForm.MyProperty =

And then Close Form

Me.Close

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Partha Protim Roy" <pa****@capoint.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
Hello Larry,

Thanks.

I tried the way you have suggested but it is not happening.

It could be the reason that my Form B is modal.

Partha
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...

"Partha Protim Roy" <pa****@capoint.com> wrote
> Hello,

> I have a Customer form say A to enter/update customer details. In
the
Form
> A I have a button which opens another form say B.
>
> In the Form B, I am providing user with a option to search Customer

from
the
> database depending on various search criteria.
>
> On matching the criteria, list of Customer is displayed in the

datagrid. > Selecting a particular row and click on OK button will do the following >
> 1. Close the Form B
>
> 2. Load the information of the selected customer in the form A.
>
>
> I am having problem in loading the information in Form A.
I am assuming your problem is in the transfer from B to A?

Give A a method to load and display the details based on a
Customer name " A.LoadDetails(CustomerName)

Give B a public function to return a string that will be your
users selection; B.GetCustomerName()

From A's button, create a form B and ask it for the name:

Dim FormB As New FormB
Dim name As String

name = FormB.GetCustomerName()
FormB = Nothing
If name.Length > 0 then LoadDetails(name)
In FormB's (Public) GetCustomerName function, load
the customer list, and show the dialog.

LoadCustomerList
Me.ShowDialog
Return UserSelection

UserSelection is a module level String variable. If the user
selects a name and hits OK, then set that UserSelection string
to the selected name, and close the form. If the user hits Cancel,
then just close the form.

The value of UserSelection will be assigned to the name variable
back in FormA after the form closes, and as shown, if there is
something in it, then use it, and if not, the user opted to cancel.

HTH
LFS



Nov 21 '05 #5

P: n/a

"Partha Protim Roy" <pa****@capoint.com> wrote

I tried the way you have suggested but it is not happening.


It should work. Try it in a new project.

Start a new project, and add a Form2. Give both Form1 and
Form2 their own button.

In Form1 use:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
Button1.Text = "Waiting..."
Button1.Text = f.GetIt
End Sub
And in Form2 use:

Private User As String

Public Function GetIt() As String
Me.ShowDialog()
Return User
End Function

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
User = "Got It"
Me.Close()
End Sub

When you run the program, clicking on the button in Form1 should
show Form2, and depending on what you do there will determine
what text is returned. If you hit the button, "Got it" will be returned
and shown on Form1' button. If you hit the X (close the form) then
Form1's button will be blank.

That works OK here....

LFS
Nov 21 '05 #6

P: n/a
Partha,

This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do it.

(There are a lot of ways to do that in VBNet)

When that is known than it is a piece of cake to help you mostly.

Maybe you can show us that.

Cor

"Partha Protim Roy"
I could not get you .

Please, write in details.

Thanks
Partha
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in
message
news:uX**************@TK2MSFTNGP10.phx.gbl...
Overload the constructor in form B

Private ParentForm As Form

Public Sub New( ByRef Parent As Form )

ParentForm = Parent

. . . .

Now you can update members of the Parent Form with search results etc
ParentForm.MyProperty =

And then Close Form

Me.Close

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Partha Protim Roy" <pa****@capoint.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
> Hello Larry,
>
> Thanks.
>
> I tried the way you have suggested but it is not happening.
>
> It could be the reason that my Form B is modal.
>
> Partha
>
>
> "Larry Serflaten" <se*******@usinternet.com> wrote in message
> news:eS**************@TK2MSFTNGP10.phx.gbl...
> >
> > "Partha Protim Roy" <pa****@capoint.com> wrote
> > > Hello,
> >
> > > I have a Customer form say A to enter/update customer details. In the > Form
> > > A I have a button which opens another form say B.
> > >
> > > In the Form B, I am providing user with a option to search Customer

from
> the
> > > database depending on various search criteria.
> > >
> > > On matching the criteria, list of Customer is displayed in the

datagrid.
> > > Selecting a particular row and click on OK button will do the

following
> > >
> > > 1. Close the Form B
> > >
> > > 2. Load the information of the selected customer in the form A.
> > >
> > >
> > > I am having problem in loading the information in Form A.
> >
> >
> > I am assuming your problem is in the transfer from B to A?
> >
> > Give A a method to load and display the details based on a
> > Customer name " A.LoadDetails(CustomerName)
> >
> > Give B a public function to return a string that will be your
> > users selection; B.GetCustomerName()
> >
> > From A's button, create a form B and ask it for the name:
> >
> > Dim FormB As New FormB
> > Dim name As String
> >
> > name = FormB.GetCustomerName()
> > FormB = Nothing
> > If name.Length > 0 then LoadDetails(name)
> >
> >
> > In FormB's (Public) GetCustomerName function, load
> > the customer list, and show the dialog.
> >
> > LoadCustomerList
> > Me.ShowDialog
> > Return UserSelection
> >
> > UserSelection is a module level String variable. If the user
> > selects a name and hits OK, then set that UserSelection string
> > to the selected name, and close the form. If the user hits Cancel,
> > then just close the form.
> >
> > The value of UserSelection will be assigned to the name variable
> > back in FormA after the form closes, and as shown, if there is
> > something in it, then use it, and if not, the user opted to cancel.
> >
> > HTH
> > LFS
> >
>
>



Nov 21 '05 #7

P: n/a

"Partha Protim Roy" <pa****@capoint.com> wrote
I could not get you .

Please, write in details.


He basically suggests to pass the new form (B), a reference to your
calling form (A) so that it can set a property of that form (A).

While it would work, it is not really an optimal solution because
the dialog (FormB) would have to know what property to call on
the calling form (FormA). If you call that same form (B) from many
other forms, they all would have to have that same property for it
to work properly.

The reverse is a bit better, give the Dialog (formB) a property that
the caller (FormA) can request after the user closes the form. But
I prefer using a public function on the form.

By using a public function, the dialog doesn't need to know anything
about who called it, only that it needs to return the name the user
selected, or an empty string if the user cancels the operation. And,
the caller makes a direct call to the form and acts on what is returned,
instead of looking at the form's properties. For a single value, it works
well. For multiple values, an object can be returned that has the multiple
values encapsulated, or, the dialog can expose properties, as was
mentioned above....

LFS

Nov 21 '05 #8

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote

This question from you, gives forever a lot of messages.
Very important is where you create your "other" form and how you do it.

(There are a lot of ways to do that in VBNet)

When that is known than it is a piece of cake to help you mostly.

Maybe you can show us that.

> > > I have a Customer form say A to enter/update customer details. In the Form
> > > A I have a button which opens another form say B.
> > >
> > > In the Form B, I am providing user with a option to search Customer from the
> > > database depending on various search criteria.

Wasn't that enoough?
LFS
Nov 21 '05 #9

P: n/a
Larry,
>> > > > I have a Customer form say A to enter/update customer details.
>> > > > In the Form
>> > > > A I have a button which opens another form say B.
>> > > >
>> > > > In the Form B, I am providing user with a option to search
>> > > > Customer from the
>> > > > database depending on various search criteria.

Wasn't that enoough?

No both can be created using an module as independent objects.
They can as well be created in one of the Forms, what makes things much
easier,
That can be as well be done with a MDIparent and MDI child, which makes it
again easier or as a dialog using a showform what makes it as well easy. (I
have seen here people here who put a button on a MDIparent by instance
before you say that cannot be done)

By instance for a showdialog the method from OHM is in my opinion the best
solutions for the question.

Maybe I forgot some however all of those make the calling of a method in
another form mostly a little bit different.

I hope this clears it?

Cor.

Nov 21 '05 #10

P: n/a
Your making the assumption that the action is being initiated by the calling
form on instantiation. This OP suggests that he wants to do a search on a
PopUp, this means the DialogResult/Or Updating the callers properties is the
best way to return a value to the caller in my opinion.

However, you are entitled to your opinion of course. There are of course
many ways to skin a rabbit as it were in .NET, thats what makes it so
versitile.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uT**************@TK2MSFTNGP11.phx.gbl...

"Partha Protim Roy" <pa****@capoint.com> wrote

I tried the way you have suggested but it is not happening.


It should work. Try it in a new project.

Start a new project, and add a Form2. Give both Form1 and
Form2 their own button.

In Form1 use:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
Button1.Text = "Waiting..."
Button1.Text = f.GetIt
End Sub
And in Form2 use:

Private User As String

Public Function GetIt() As String
Me.ShowDialog()
Return User
End Function

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
User = "Got It"
Me.Close()
End Sub

When you run the program, clicking on the button in Form1 should
show Form2, and depending on what you do there will determine
what text is returned. If you hit the button, "Got it" will be returned
and shown on Form1' button. If you hit the X (close the form) then
Form1's button will be blank.

That works OK here....

LFS

Nov 21 '05 #11

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote
Wasn't that enoough?
No both can be created using an module as independent objects.

<...> I hope this clears it?
I do not see the many different cases you see. It matters little if the
forms are SDI or MDI child forms. The OP said one form called
another. That seems pretty plain to me.

By instance for a showdialog the method from OHM is in my opinion the best
solutions for the question.


OHM suggested passing in the Parent form reference and then
calling a property on the calling form:

Private ParentForm As Form

Public Sub New( ByRef Parent As Form )
ParentForm = Parent

......

And when closing:

ParentForm.MyProperty = "George"
Me.Close
But, that forces the Parent form to expose a Public MyProperty.

If FormA calls that dialog, it has to expose FormA.MyProperty
If FormAA calls that dialog, it has to expose FormAA.MyProperty
If FormAAA calls that dialog, it has to expose FormAAA.MyProperty

Do you see what the problem is with that method?

Consider how the FileOpen dialog handles that same situation:

Dim openFile As New System.Windows.Forms.OpenFileDialog
openFile.ShowDialog()
Name = openFile.FileName

Here, the dialog exposes the property, not the calling form. That
is preferrable than having the parent expose the property.
Consider the InputBox:

name = InputBox("", "Enter Customer")

This is like the suggestion I made. The caller gets the user's value
returned from the call.

Now, here is the big question. Can you show me an example that
is included in the NET Framework, where the caller exposes a property
for the dialog to set? (Like OHM's suggestion?)

<g>
LFS


Nov 21 '05 #12

P: n/a
Thank you very much.

It is working fine.

Once again thank u Larry

Partha
"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:uT**************@TK2MSFTNGP11.phx.gbl...

"Partha Protim Roy" <pa****@capoint.com> wrote

I tried the way you have suggested but it is not happening.


It should work. Try it in a new project.

Start a new project, and add a Form2. Give both Form1 and
Form2 their own button.

In Form1 use:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
Button1.Text = "Waiting..."
Button1.Text = f.GetIt
End Sub
And in Form2 use:

Private User As String

Public Function GetIt() As String
Me.ShowDialog()
Return User
End Function

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
User = "Got It"
Me.Close()
End Sub

When you run the program, clicking on the button in Form1 should
show Form2, and depending on what you do there will determine
what text is returned. If you hit the button, "Got it" will be returned
and shown on Form1' button. If you hit the X (close the form) then
Form1's button will be blank.

That works OK here....

LFS

Nov 21 '05 #13

P: n/a
Larry,
I do not see the many different cases you see. It matters little if the
forms are SDI or MDI child forms. The OP said one form called
another. That seems pretty plain to me.
Called can be in my opinion be call the method not instance the Form as new
form, that it is unclear for me is in my opinion enough to have doubts, not
that I am right, I have doubts where you can be right by the way.
By instance for a showdialog the method from OHM is in my opinion the
best
solutions for the question.


OHM suggested passing in the Parent form reference and then
calling a property on the calling form:

You are right, I did only look at the overloaded instancing. When it is a
showdialogform, than it is very sufficient (again in my opinion)

By the way, Larry, I did not say that your solution is wrong, my reaction
was on the message from the OP and the many long threads about this subjects
that I have seen about this. Where at the end was by instance showed that
the the Op was creating everytime a new form while he did wanted to access a
method on a previous. That was the reason of my message. I did only slightly
look at your solution and thought that you took 2 ways the form could be
instanced.

When the OP tell us how he instances his forms, than all becomes in my idea
much easier.

Cor

Nov 21 '05 #14

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
Your making the assumption that the action is being initiated by the calling
form on instantiation.
That is a little vague. I made no assumtion other than the OP wanted to show
a list of names to the user, and have the user select one from the list. The
problem was in learning what name the user selected.

This OP suggests that he wants to do a search on a PopUp,
I don't understand that at all. A search on a PopUp? Isn't a PopUp some
form of context menu? There was no mention of menus that I saw....

this means the DialogResult/Or Updating the callers properties is the
best way to return a value to the caller in my opinion.

However, you are entitled to your opinion of course.


Yes, I can agree there! (Whew!)

But, see my reply to Cor. What dialog in the .NET framework acts
as you suggest? If it is the best type to use for dialogs, where is
it in the NET framework class library? Did MSFT purposely use
'lower grade' dialogs??? <g>

LFS
Nov 21 '05 #15

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote
You are right, I did only look at the overloaded instancing. When it is a
showdialogform, than it is very sufficient (again in my opinion)

By the way, Larry, I did not say that your solution is wrong, my reaction
was on the message from the OP and the many long threads about this subjects
that I have seen about this. Where at the end was by instance showed that
the the Op was creating everytime a new form while he did wanted to access a
method on a previous.


Aha! I now see why you said it matters how the form was created. But, it
was fairly evident from the first post, that the use was to be like a standard
dialog form. The form was to show, get input, and close. I would have also
offered something different if the form was not modal, and was loaded
previously.

LFS
Nov 21 '05 #16

P: n/a
Lets look at the OP's post once again . . .
I have a Customer form say A to enter/update customer details. In the Form
A I have a button which opens another form say B. OK, we all agree to instantiate a object of Type Form(B) !
In the Form B, I am providing user with a option to search Customer from thedatabase depending on various search criteria.
On matching the criteria, list of Customer is displayed in the datagrid.
Selecting a particular row and click on OK button will do the following


This implies that after the form is instantiated, the user will perform a
search and then close the form. Your code Initialises form B's User property
asynchronsously and at any time after this, the user performs the search
then closes the form. Do you see the problem with this approach.?

The emphasis should be to drive it from form B. If the user uses the
..ShowDialog Method, this enables us to Sychronously execute some statements
which would allow us to interrogate the B's properties or methods of Friend
of Above. The B's Closure can be a Hide() instead and the B.Close() method
can be called after retreiving the data. This is a better method actually in
my opinion than yours.

However, I will conceed that revealing A's Method or Properties with a view
to B setting them is perhaps not the best way to do it, however, it's still
valid as an answer.

Regards - OHM
Nov 21 '05 #17

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
OK, we all agree to instantiate a object of Type Form(B) !
Yep

In the Form B, I am providing user with a option to search Customer from

the
database depending on various search criteria.
On matching the criteria, list of Customer is displayed in the datagrid.
Selecting a particular row and click on OK button will do the following


This implies that after the form is instantiated, the user will perform a
search and then close the form.


The user will perform a search
Select an item from the results of that search
Then close the form

Your code Initialises form B's User property
asynchronsously and at any time after this, the user performs the search
then closes the form. Do you see the problem with this approach.?
You did not follow along, or you got confused somewhere.
The (private) User is set in the click event of the OK button.
That would be after they did the search and selected a name.

The value that was set in the OK button is the value that is
returned from the function. Set up the example and try it
for yourself. As I indicated, it functions much like the
InputBox function. (For example, put a textbox on the 2nd
form, and enter text into it. Then in the button click event,
assign that text to the User variable and see for yourself that
your text does get returned.)

However, I will conceed that revealing A's Method or Properties with a view
to B setting them is perhaps not the best way to do it, however, it's still
valid as an answer.


OK, you've seen the light, but what about Cor, who also
thought your suggestion was the best method???

he he
LFS
Nov 21 '05 #18

P: n/a

"Larry Serflaten"
OK, you've seen the light, but what about Cor, who also
thought your suggestion was the best method???
Where?
By instance for a showdialog the method from OHM is in my opinion the best
solutions for the question.


This one from me. As you showed me did Terry not use a showdialog, so this
is not a little bit wrong as text but almost completly as what I wrote in my
previous message.

I still did not investigate as it I told in the prevous message, if this is
a challenge to do it better I will gladly accept, however I think with that
we will not win much, so better not.

Or is it only to enjoy it extra for you and to show it to us, than I am
happy with you.

:-))))

Cor
Nov 21 '05 #19

P: n/a
OK, your right I conceed that your method will work. I still think that mine
is cleaner and easier to read.

//Calling Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles searchButton.Click
Dim searchForm As New B
Dim DResult As DialogResult

DResult = searchForm.ShowDialog()
Select Case DResult
Case DialogResult.OK
Me.returnedText.Text = searchForm.UserName
Case DialogResult.Cancel
Me.returnedText.Text = "Cancelled"
End Select
searchForm.Close()
End Sub

//Called Form
Private m_UserName As String

Public ReadOnly Property UserName() As String
Get
Return m_UserName
End Get
End Property

Private Sub okButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles okButton.Click
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub

Private Sub canelButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles canelButton.Click
Me.DialogResult = DialogResult.Cancel
Me.Hide()
End Sub

Private Sub returnTextBox_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles returnTextBox.TextChanged
m_UserName = Me.returnTextBox.Text
End Sub

Nov 21 '05 #20

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
OK, your right I conceed that your method will work. I still think that mine
is cleaner and easier to read.

Dim searchForm As New B
Dim DResult As DialogResult

DResult = searchForm.ShowDialog()
Select Case DResult
Case DialogResult.OK
Me.returnedText.Text = searchForm.UserName
Case DialogResult.Cancel
Me.returnedText.Text = "Cancelled"
End Select
searchForm.Close()
Compare those 10 lines to these 7:

Dim User As New Form2
Dim data As String = User.GetData()

If data Is Nothing Then
MsgBox("User canceled")
Else
MsgBox(data)
End If
Yours is easier to read?

Whats with all that extra code? <g>

//Called Form
Private m_UserName As String Private Sub okButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles okButton.Click
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub


What is Hide adding to your code here? (comment it out?)

Now compare your 17 lines of Form2 code to these 12:

Private mUser As String

Public Function GetData() As String
Me.ShowDialog()
Return mUser
End Function

Private Sub OK_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOK.Click
mUser = TextBox1.Text
Me.Close()
End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub

Are you still thinking yours is cleaner, and easier to read?

The fact that you require your calling forms to know the proper
property to use after the call is a minor strike against that method
when (as you see) it is not required.

Do as you see fit, they both work, but as you may know, the more
code you add to aprogram, the more there is that can go wrong.

But here is the kicker!

Suppose you wanted to adapt that dialog to a different purpose?
Suppose now, you want to use it to return the name of a country,
or as in the original case, a selection from an entirely different list.

Do you add a new Property called UserCountry? And in the
case of the list, how does the form know which list to load?

In my case, I would add a new Function GetItem and that
new routine could set up the form for the added functionality,
and return the new data.

So, IMHO, my method is a little bit more forward looking,
in that it can easily be made to accomodate added functionality
without requireing changes to the code that already put it to
use.

In your case, you might give it a property to tell it which list
to load, but if you did that, you'd have to go back in your
code to update all those places it was used, to add a line
to set that property to its required value. That 'resistance
to change' also makes the call and query method a bit less
useful....

IMHO you have to keep an eye on allowing your objects
to be modified without causing a major impact on previous
code. If you can do that, without undue jumping through
hoops, then that would be the more favored approach in
my book.

LFS

Nov 21 '05 #21

P: n/a
Your point is noted. I think you don't like to be bettered, and hence will
always look for an argument to make yourself so.

Good luck in your endeavours, I think that you probably don't get much sleep
at night worrying about how you could improve yourself.
Stay Lucky - OHM

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eG*************@TK2MSFTNGP12.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
OK, your right I conceed that your method will work. I still think that mine is cleaner and easier to read.

Dim searchForm As New B
Dim DResult As DialogResult

DResult = searchForm.ShowDialog()
Select Case DResult
Case DialogResult.OK
Me.returnedText.Text = searchForm.UserName
Case DialogResult.Cancel
Me.returnedText.Text = "Cancelled"
End Select
searchForm.Close()


Compare those 10 lines to these 7:

Dim User As New Form2
Dim data As String = User.GetData()

If data Is Nothing Then
MsgBox("User canceled")
Else
MsgBox(data)
End If
Yours is easier to read?

Whats with all that extra code? <g>

//Called Form
Private m_UserName As String

Private Sub okButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles okButton.Click
Me.DialogResult = DialogResult.OK
Me.Hide()
End Sub


What is Hide adding to your code here? (comment it out?)

Now compare your 17 lines of Form2 code to these 12:

Private mUser As String

Public Function GetData() As String
Me.ShowDialog()
Return mUser
End Function

Private Sub OK_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOK.Click
mUser = TextBox1.Text
Me.Close()
End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub

Are you still thinking yours is cleaner, and easier to read?

The fact that you require your calling forms to know the proper
property to use after the call is a minor strike against that method
when (as you see) it is not required.

Do as you see fit, they both work, but as you may know, the more
code you add to aprogram, the more there is that can go wrong.

But here is the kicker!

Suppose you wanted to adapt that dialog to a different purpose?
Suppose now, you want to use it to return the name of a country,
or as in the original case, a selection from an entirely different list.

Do you add a new Property called UserCountry? And in the
case of the list, how does the form know which list to load?

In my case, I would add a new Function GetItem and that
new routine could set up the form for the added functionality,
and return the new data.

So, IMHO, my method is a little bit more forward looking,
in that it can easily be made to accomodate added functionality
without requireing changes to the code that already put it to
use.

In your case, you might give it a property to tell it which list
to load, but if you did that, you'd have to go back in your
code to update all those places it was used, to add a line
to set that property to its required value. That 'resistance
to change' also makes the call and query method a bit less
useful....

IMHO you have to keep an eye on allowing your objects
to be modified without causing a major impact on previous
code. If you can do that, without undue jumping through
hoops, then that would be the more favored approach in
my book.

LFS


Nov 21 '05 #22

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
Your point is noted. I think you don't like to be bettered, and hence will
always look for an argument to make yourself so.


A statement like ' I like my code better ' is of no value unless there are
good reasons why that method is a better choice.

These groups go around the globe, and are archived for several years.
Its one thing to say, 'this is how you do that', but it is completely
different to say 'this is why you do that this way'.

Everyone reading the thread will be better informed if the reasoning
is included (where appropreate) than when just a snippette of code
is posted. That is why I went through the trouble of comparing the
two methods. They both work, so why choose one over the other?

With the added comments, the reader is better informed to make up
their own mind about which to use in their own situation....

There is always the chance that someone else may jump in with
yet a better method. When then happens, in this case, then I might
be in your shoes and find my method was maybe not the best.
But the casual reader/lurker would then be educated even further!

That is what makes these groups such a good tool for learning!

LFS

Nov 21 '05 #23

P: n/a
Good Luck - OHM

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eC****************@TK2MSFTNGP10.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
Your point is noted. I think you don't like to be bettered, and hence will always look for an argument to make yourself so.


A statement like ' I like my code better ' is of no value unless there are
good reasons why that method is a better choice.

These groups go around the globe, and are archived for several years.
Its one thing to say, 'this is how you do that', but it is completely
different to say 'this is why you do that this way'.

Everyone reading the thread will be better informed if the reasoning
is included (where appropreate) than when just a snippette of code
is posted. That is why I went through the trouble of comparing the
two methods. They both work, so why choose one over the other?

With the added comments, the reader is better informed to make up
their own mind about which to use in their own situation....

There is always the chance that someone else may jump in with
yet a better method. When then happens, in this case, then I might
be in your shoes and find my method was maybe not the best.
But the casual reader/lurker would then be educated even further!

That is what makes these groups such a good tool for learning!

LFS

Nov 21 '05 #24

P: n/a
Larry,
With the added comments, the reader is better informed to make up
their own mind about which to use in their own situation....

Depends if it is real a global question, when somebody asks how can I add 5
to 5, I think than that telling why you did use an integer instead of a
double is a little bit overdone.

In my opinion needs a snippet no comments until the OP or somebody else
starts asking questions about it.

However just my opinion.

Cor
Nov 21 '05 #25

P: n/a
I agree.

Using ones experience to help others in a positive way engenders a sense of
community with mentoring, However, being aloof and using the shortfalls of
others to widen the (perceived) gap between one's capability and the
capability of others does little for the community and breeds resentment.

It is not always necessary to debate things to the Nth degree just to gain a
final advantage. Whilst I agree all things can be rationalised down to a
finite level to obtain a 'best practice' or 'best solution', life is seldom
kind enough to give us the time to do so, and if we did, we may never
achieve the end game because we spent all our time at the macro level
debating which is best.

OHM
Nov 21 '05 #26

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote
With the added comments, the reader is better informed to make up
their own mind about which to use in their own situation....
Depends if it is real a global question, when somebody asks how can I add 5
to 5, I think than that telling why you did use an integer instead of a
double is a little bit overdone.


I agree, and I even said so:
Everyone reading the thread will be better informed if the reasoning
is included (where appropreate) than when just a snippette of code
is posted.


That '(where appropreate)' addresses your concern. In the case you
mention, trying to say why an integer was used, isn't appropreate.

You know how many times a question like this has been asked:
"This question from you, gives forever a lot of messages."


In this thread alone, there were 3 different methods suggested, so
adding a bit of information on deciding which to choose is going
to help those who also have need to pass variables to or from a
second form.

LFS
Nov 21 '05 #27

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
However, being aloof and using the shortfalls of
others to widen the (perceived) gap between one's capability and the
capability of others does little for the community and breeds resentment.
I have been participating in newsgroups for several years. They are an
excellent medium to hold informative discussions. One thing that is pretty
common is that nobody likes hearing someone say 'Your method is wrong'
when the darn thing works and gets the job done.

But I didn't say that, the major reason I continued at all was because of
Cor's reply:
By instance for a showdialog the method from OHM is in my opinion the
best solutions for the question.
If it turns out there are better solutions, then it would be in everyone's best interest
to get Cor to change his opinion to the better solution so that the next time that
question gets asked, he can offer the better solution. As you know Cor posts a
lot of messages, and helps many people, so getting him to see 'why' one solution is
better than another will 'maybe' persuade him to change his opinion of the best
solution for the task.

It is not always necessary to debate things to the Nth degree just to gain a
final advantage.
See above, this particular question is asked fairly often, (and may continue
to be asked often) so getting people who post replies familiar with a
'best practises' solution is going to benefit the most people.
Whilst I agree all things can be rationalised down to a
finite level to obtain a 'best practice' or 'best solution', life is seldom
kind enough to give us the time to do so, and if we did, we may never
achieve the end game because we spent all our time at the macro level
debating which is best.


I did not intend to be aloof, or to put down anyone. Look at it as you
would a bit of optimization. You don't optimize every line of code and
every routine in your program. You profile where it would do the most
good, and concentrate on that. As I said, Cor answers a lot of questions,
and and many listen to what he says. I also know that he may see this same
question again and again. Therefore, if I explain why one solution works
better than others, and if he is open enough to change his opinion to the
better solution, then many others who ask this same question have a better
chance at hearing the 'best practises' solution, and not the one you agreed
is not the best one for the job.

I am not singling out Cor as the only one who answers questions, he does
post a lot however. I can only wonder what your response will be the next
time you see a similar question!

<g>
LFS


Nov 21 '05 #28

P: n/a
It's just in your nature Larry, admit it, you just have to have the last
word don't you ?

;-)

Your points are noted. The important thing is however, is how you put those
points across. Try being a little less challenging, coaxing a person to see
where they could improve their code by 'pleasantly' asking the right
questions is far more likely to bring about a state of cognition in the
respondent, than making lightly veiled derisory remarks which usually cause
a push back.

I can see that you are equipped to make a cogent argument for yourself in
the subject matter, however, in a community 'Even an on-line community' such
as this. Relationships between contributors are everything.

The written word, can sometimes convey emotions which were never intended
and stimulate resentment and bad feeling, so sometimes one has to be overly
polite when talking about potentially inflaming things.

I hope you can see the rational I am trying to put across.
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:eV**************@TK2MSFTNGP11.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
However, being aloof and using the shortfalls of
others to widen the (perceived) gap between one's capability and the
capability of others does little for the community and breeds resentment.

I have been participating in newsgroups for several years. They are an
excellent medium to hold informative discussions. One thing that is pretty common is that nobody likes hearing someone say 'Your method is wrong'
when the darn thing works and gets the job done.

But I didn't say that, the major reason I continued at all was because of
Cor's reply:
By instance for a showdialog the method from OHM is in my opinion the
best solutions for the question.
If it turns out there are better solutions, then it would be in everyone's

best interest to get Cor to change his opinion to the better solution so that the next time that question gets asked, he can offer the better solution. As you know Cor posts a lot of messages, and helps many people, so getting him to see 'why' one solution is better than another will 'maybe' persuade him to change his opinion of the best solution for the task.

It is not always necessary to debate things to the Nth degree just to
gain a final advantage.


See above, this particular question is asked fairly often, (and may

continue to be asked often) so getting people who post replies familiar with a
'best practises' solution is going to benefit the most people.
Whilst I agree all things can be rationalised down to a
finite level to obtain a 'best practice' or 'best solution', life is seldom kind enough to give us the time to do so, and if we did, we may never
achieve the end game because we spent all our time at the macro level
debating which is best.
I did not intend to be aloof, or to put down anyone. Look at it as you
would a bit of optimization. You don't optimize every line of code and
every routine in your program. You profile where it would do the most
good, and concentrate on that. As I said, Cor answers a lot of questions,
and and many listen to what he says. I also know that he may see this

same question again and again. Therefore, if I explain why one solution works
better than others, and if he is open enough to change his opinion to the
better solution, then many others who ask this same question have a better
chance at hearing the 'best practises' solution, and not the one you agreed is not the best one for the job.

I am not singling out Cor as the only one who answers questions, he does
post a lot however. I can only wonder what your response will be the next
time you see a similar question!

<g>
LFS


Nov 21 '05 #29

P: n/a

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
It's just in your nature Larry, admit it, you just have to have the last
word don't you ?
There's a catch 22 question if there ever was one....
;-)
Your points are noted. The important thing is however, is how you put those
points across. Try being a little less challenging,
Noted....

<...> I hope you can see the rational I am trying to put across.


I do, and hope later encounters will show some improvement on my end....

Thanks!
LFS
Nov 21 '05 #30

P: n/a
Hi Larry

What did you construct in the message above I only wrote the first part.

I don't know the rest which seems from me, I do not like that.

Cor
Nov 21 '05 #31

P: n/a
Your welcome. No hard feelings here.

END

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Larry Serflaten" <se*******@usinternet.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
It's just in your nature Larry, admit it, you just have to have the last
word don't you ?


There's a catch 22 question if there ever was one....
;-)


Your points are noted. The important thing is however, is how you put those points across. Try being a little less challenging,


Noted....

<...>
I hope you can see the rational I am trying to put across.


I do, and hope later encounters will show some improvement on my end....

Thanks!
LFS

Nov 21 '05 #32

P: n/a
Larry,
But I didn't say that, the major reason I continued at all was because of
Cor's reply:

Do you mean the last messages I have send in what I said that I saw it wrong
in my first message and that the method from Terry was probably not the
best. Do you now tell that the method from Terry is the best?

However the OP has only told this.
----------------------------------------------------------------------------
I have a Customer form say A to enter/update customer details. In the Form
A I have a button which opens another form say B.

In the Form B, I am providing user with a option to search Customer from the
database depending on various search criteria.
------------------------------------------------------------------------------

When this is about two MDI forms the change is that all your solutions would
probably have been completly wrong. (I did not investigage this whole
thread). Terry did it better, so he can maybe tell that?

Cor
Nov 21 '05 #33

P: n/a

"Cor Ligthert" <no************@planet.nl> wrote

What did you construct in the message above I only wrote the first part.

I don't know the rest which seems from me, I do not like that.


I do not mean to insult you. Read in context, my message explains
that you already know the question "How to pass data from form to form"
gets asked a lot.

That is what was meant by:

---------------
You know how many times a question like this has been asked:
"This question from you, gives forever a lot of messages."

--------------

I said; you have seen this question many times. Nothing more.

After that I said:

"adding a bit of information on deciding which to choose is going
to help those who also have need to pass variables to or from a
second form"

I also do not like to be quoted 'out of context', but this was not
a bad quote 'out of context'. It was an affirmation (by agreeing) with
what you said.

HTH
LFS
Nov 21 '05 #34

This discussion thread is closed

Replies have been disabled for this discussion.