473,765 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sub Form Getting Values from the Parent Form

I have a "parent" form (if that's the right terminology), Form1. I
declare two public values in the parent form :
Public Class Form1
Inherits System.Windows. Forms.Form
Public CurDir As String = Directory.GetCu rrentDirectory( ) 'used
by FormGetJobOutpu t
Public PubUser As String 'tbxUser.text value for subForms

In the "child" form, I call it FormGetJobOutpu t, I reference these two
public values ...
Sub CreateGetJobOut putScript(ByVal filename As String)
Dim swScriptFile As New System.IO.Strea mWriter(CurDir( ) + "\"
+ filename, True)
swScriptFile.Wr iteLine("open xxx.xxxx.com")
swScriptFile.Wr iteLine(PubUser )

The reference to CurDir works fine. (Although there is something a
bit strange about it. I type "CurDir" but VS adds the parens. I have
no idea why. But VB.Net seems to be happy with that syntax and it
executes fine. But the reference to PubUser results in error message
"Name 'PubUser' is not declared. If I use Form1.PubUser I get error
"Reference to a non-shared member requires an object reference."
I also tried a different declare for PubUser (Public PubUser As String
= "") but that also did not help.

What do I have to do to use PubUser in the child form? Why can I
reference CurDir but not PubUser?

Thanks, Bob
Nov 21 '05 #1
4 2812
eBob.com wrote:
I have a "parent" form (if that's the right terminology), Form1. I
declare two public values in the parent form :
Public Class Form1
Inherits System.Windows. Forms.Form
Public CurDir As String = Directory.GetCu rrentDirectory( ) 'used
by FormGetJobOutpu t
Public PubUser As String 'tbxUser.text value for subForms

In the "child" form, I call it FormGetJobOutpu t, I reference these two
public values ...
Sub CreateGetJobOut putScript(ByVal filename As String)
Dim swScriptFile As New System.IO.Strea mWriter(CurDir( ) + "\"
+ filename, True)
swScriptFile.Wr iteLine("open xxx.xxxx.com")
swScriptFile.Wr iteLine(PubUser )

The reference to CurDir works fine. (Although there is something a
bit strange about it. I type "CurDir" but VS adds the parens. I have
no idea why. But VB.Net seems to be happy with that syntax and it
executes fine. But the reference to PubUser results in error message
"Name 'PubUser' is not declared. If I use Form1.PubUser I get error
"Reference to a non-shared member requires an object reference."
I also tried a different declare for PubUser (Public PubUser As String
= "") but that also did not help.

What do I have to do to use PubUser in the child form? Why can I
reference CurDir but not PubUser?

Thanks, Bob


Your child form has to have a reference to the parent. Form1.PubUser
doesn't work cause Form1 is a class definition not an instatance of the
class. How are you opening child form? You could do something like:

Class Child
Parent as Form1
...... All your stuff
public shadows sub ShowDialog(Valu e as Form1)
Parent = Value
End Sub

Sub CreateGetJobOut putScript(ByVal filename As String)
Dim swScriptFile As New System.IO.Strea mWriter(Parnet. CurDir()
+ "\" + filename, True)
swScriptFile.Wr iteLine("open xxx.xxxx.com")
swScriptFile.Wr iteLine(Parnet. PubUser)
..........
End sub
End Class

This way whenever you open Child you have to pass in his parent.

Lots of other ways to do it, can you make a property to hold it. There
may be an owner property that will hold it already but I can't remember
off the top of my head...

Chris
Nov 21 '05 #2
eBob,

Two points

What is your currentdirector y. If it is something that you want to save for
the user than a good place for that is the registry, when the user than
restart it has a nice start point without intitializing that again.

Your current user can you save in by instance a shared sub.
\\\
Public Class Variables
Private Shared mUserName As String
Friend Shared Property Username() As String
Get
Return mUserName
End Get
Set(ByVal Value As String)
mUserName = Value
End Set
End Property
End Class
////

Use this only for that what is really needed on all forms. It is a fixed
part of your program and uses therefore all the time the memory.

I hope this helps,

Cor
Nov 21 '05 #3
On Thu, 25 Aug 2005 23:35:11 -0400, eBob.com
<eB******@total lyfakeisp.com> wrote:

Thank you Chris and Cor. I appreciate your help. But you were both a
bit over my head. I am a real novice. I finally remembered a
technique I've used in the past. I declared some Public variables in
the child class and set them in the parent form after instantiating
the child but before the child.Show()

Thanks, Bob
Nov 21 '05 #4
erBob,

Probably by *putting* it in that form

\\\
dim frm as new form2
frm2.curdir = curdir
frm2.user = user
frm2.showdialog
///

I hope this helps,

Cor
Nov 21 '05 #5

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

Similar topics

25
10264
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the data in each record, which includes the ID of the father and the mother (who also have records in the table). One record per form. I have a Tab Control in the form, and in one of the tabs I have a subform (sfmSiblings) in which I wish to list...
11
18836
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion that will also either a) stretch the form width wise on widescreens or b), rely on height rather than...
2
6969
by: Chandru | last post by:
hi I want to know how to pass values from different forms. That is, i created one parent form. from there i opened child form modeless way. Once i close the child form i need some value from child form that to be transferred in Parent form. thanks in advance.
1
4016
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone field on the parent table and the code Child form public DataRowView SelectedAddres ge ...
16
453
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub in the Parent form and reference a child mdi form like this: Sub ReadText()
2
4288
by: Rich | last post by:
Greetings. I have a child form inside an MID parent form. The child form is wider than the MID parent form. The child form contains a number of textboxes which are positioned from left to right on the child form where the textbox on the right is not viewable because it extends beyond the right border of the MDI parent form. What I need to happen is when I tab through the textboxes - when I tab into the textbox on the right side of...
3
4692
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The form that has the System.Windows.Forms.LinkLabel controls on it is in a different project and under a different namespace from the file where the LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog under the LinkClicked method. ...
3
1672
by: arunvasuki | last post by:
Hi, I have a form with a few edit boxes. In the form i also have a search button which takes me to a small pop up window. After searching i am getting back the values in to the parent form..also the parent form is getting refeshed but the values are not retained..could some one tell me how to retain the values... thanks
0
9568
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
9404
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
10164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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...
0
9835
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...
1
7379
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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
3
2806
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.