473,406 Members | 2,713 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,406 software developers and data experts.

make a form shared - called from another form - how?

Hello,

I have a child form in an Mdi Parent form. I have 5 menu buttons on the
Parent that I use to show the child form. Originally, in the Parent form on
load event I had this line of code

frmChild.MdiParent = Me

But then, I added an argument to the constructor of the child form. Now I
get the error message for the line of code frmChild.MdiParent = Me. Error
say:

"Reference to a non-shared member requires and Object Reference"

So in each of the Menu buttons I now have
Dim frm As New frmChild
frm.MdiParent = Me
frm.Show

I want to eliminate the redundant line of code frm.MdiParent = Me. How do I
make the Child form shared? I tried placing the word "Shared" next to the
constructor of frmchild, but got an error. How to make the form shared?

Thanks,
Rich
May 25 '06 #1
4 2305
The error you're getting means that you're referring to a class, not an
object. In your message, you mention that the error comes on this line:
frmChild.MdiParent = Me
But then in your quoted code, you use
Dim frm As New frmChild
frm.MdiParent = Me


Note the difference: frm is an instance, frmChild is a class. So the
first snippet doesn't make sense: "frmChild" is a class, not an
instance of a class. I'm unclear about what you mean about adding an
argument to the constructor... do you mean that you pass a form
reference to the child form and have it set its own MdiParent property?
You could do that, sure; in the overloaded New() sub, pass a reference
to the parent as a parameter and then set

Me.MdiParent = theParameter

It's worth noting that in VB6, frmChild referred both to the form
"class" *and* to a default instance of the form; a lot of transitioning
coders run into this problem.

Hope that helps.

g.

May 25 '06 #2
Thank you for your reply. This is very informative. Now to explain a little
more what I am doing:

I have one parent MDI form and one child form. I am using the Parent MDI
form to take advantage of the scroll bars because the user of my app has a
resolution that really restricts screen realestate - thus the scroll bars (I
have several pannels and splitters, ... on the child form - did not want to
bother with scrollbars). The child form gets data from our sql server. Each
menu button on the parent form passes a param to the child form to pick up
different rows from sql server. With each menu button on the Parent mdi, I
close the child form and re-open it as new. From what you are suggesting, I
get the idea that I do not need to keep reloading the child form. I would
rather load the child form once and pass the parameter to it from the parent
through the menubutton - but I have to reload the data.

I tried using a public sub - which I was able to reload the data by invoking
it from the parent, but the datagrids on the child did not refresh/update.
The only way I was able to get the datagrids on the child to refresh/update
was to close child and reopen child with the new parameter. Is there a way
I could open the child form once and reload/refresh the data from the Parent
Mdi form without having to reopen the child form?

Thanks,
Rich

"Graham Charles" wrote:
The error you're getting means that you're referring to a class, not an
object. In your message, you mention that the error comes on this line:
frmChild.MdiParent = Me


But then in your quoted code, you use
Dim frm As New frmChild
frm.MdiParent = Me


Note the difference: frm is an instance, frmChild is a class. So the
first snippet doesn't make sense: "frmChild" is a class, not an
instance of a class. I'm unclear about what you mean about adding an
argument to the constructor... do you mean that you pass a form
reference to the child form and have it set its own MdiParent property?
You could do that, sure; in the overloaded New() sub, pass a reference
to the parent as a parameter and then set

Me.MdiParent = theParameter

It's worth noting that in VB6, frmChild referred both to the form
"class" *and* to a default instance of the form; a lot of transitioning
coders run into this problem.

Hope that helps.

g.

May 25 '06 #3
I am the slow one. I finally figured out what you meant about passing a
reference to the child form of the Parent in the overloaded constructor of th
child form. That is working. Except VB2005 is passing it ByVal instead of
ByRef. Don't know if that makes any difference. The app seems to work OK.

"Graham Charles" wrote:
The error you're getting means that you're referring to a class, not an
object. In your message, you mention that the error comes on this line:
frmChild.MdiParent = Me


But then in your quoted code, you use
Dim frm As New frmChild
frm.MdiParent = Me


Note the difference: frm is an instance, frmChild is a class. So the
first snippet doesn't make sense: "frmChild" is a class, not an
instance of a class. I'm unclear about what you mean about adding an
argument to the constructor... do you mean that you pass a form
reference to the child form and have it set its own MdiParent property?
You could do that, sure; in the overloaded New() sub, pass a reference
to the parent as a parameter and then set

Me.MdiParent = theParameter

It's worth noting that in VB6, frmChild referred both to the form
"class" *and* to a default instance of the form; a lot of transitioning
coders run into this problem.

Hope that helps.

g.

May 25 '06 #4
You shouldn't have to reload your child form, no... you just need a
procedure that refreshes the data on the child form.

g.

May 26 '06 #5

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

Similar topics

5
by: Ivan | last post by:
I am used to VB6 and am not sure how to do this in Vstudio .NET. I have a main form which calls other forms. I want to disable that main form while other ones are called. I tried hiding it and...
8
by: Mike Caputo | last post by:
In VB.NET, need to be able to access certain properties on my main form from other forms. These are properties that may be changed by the user, so I have to be able to get to them throughout the...
0
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is...
4
by: Chris Ashley | last post by:
I have a class called App set as the startup object with the following code: Friend Class App Shared Sub Main() Dim FrmMain As New MainForm Application.Run(FrmMain) End Sub End Class In...
6
by: Samuel R. Neff | last post by:
I'm having weird results with a form that is already displayed modally (via ShowDialog) displaying a second form via ShowDialog. The last form is not modal even though it's called with ShowDialog....
5
by: Mrozu | last post by:
Hi I have frm1. On this form button.Click code for this button is: Dim frm2 as New frm2 frm2.show So after click, frm2 form is shown.
2
by: HmFireBall | last post by:
Hi, This is a question about a shared property in ASP.NET Imagine there's an assembly called my.dll that is in the /bin directory of several websites. This assembly contains a class with a...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET, or any VB. I need to have form1 call form2 which calls form3, etc. I am able to use oledb in form1 to get the data. I build all the data for form2 and form3 from...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
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: 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
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.