vellaima Posted February 4, 2003 Posted February 4, 2003 Hello, Public Class salesrepadd Inherits System.Windows.Forms.Form Private Sub Add() address.text = "Trial" Dim ins As New InsertSalesRep() ins.insert() End Sub End Class Public Class InsertSalesRep Inherits salesrepadd Public Sub insert() MsgBox(address.Text) ------> Displays blank End Sub End Class In the above program eventhough i have inherited the window form i am not able to retreive the values of the textbox etc.,. Could you please tell me where have i gone wrong. Quote
Leaders quwiltw Posted February 4, 2003 Leaders Posted February 4, 2003 Did you just leave out the constructor for simplification or is there no constructor where you explicitly call the parent forms constructor as in MyBase.New()? Edit: ok so maybe I was on the wrong path....:( Quote --tim
vellaima Posted February 4, 2003 Author Posted February 4, 2003 I have just highlighted where the problem is occuring. Quote
*Gurus* divil Posted February 4, 2003 *Gurus* Posted February 4, 2003 They are totally separate classes. Your second class has no knowledge of the first one's textbox called "address". To rectify this, you could pass the textbox to the Insert routine in the second class, or associate the second class with the first when you create it, in the constructor. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
vellaima Posted February 4, 2003 Author Posted February 4, 2003 Can you please tell me how to associate the second class with the first in the constructor as i am new VB.NET. Quote
Leaders quwiltw Posted February 4, 2003 Leaders Posted February 4, 2003 he's inheriting the first in the second, so he does have access to it without passing references. are these hand-coded inherited forms or are you using visual studio? Quote --tim
Leaders quwiltw Posted February 4, 2003 Leaders Posted February 4, 2003 in the constructor you just need to call the base classes new ie. MyBase.New() but Visual Studio.NET takes care of this setup stuff for you if you're using it. Quote --tim
vellaima Posted February 4, 2003 Author Posted February 4, 2003 The problem i am having is i am not able to get the values of the textboxes in the class InsertSalesRep. Can anyone please help me solve this problem. Sample code will be helpful. Quote
Leaders quwiltw Posted February 4, 2003 Leaders Posted February 4, 2003 You've given us limited insight into what is exactly going on here. Why don't you attach the entire code for both classes? Quote --tim
Leaders quwiltw Posted February 4, 2003 Leaders Posted February 4, 2003 Trimmed a bit (hopefully I didn't snip any of the important stuff) but.... Public Class Form1 Inherits System.Windows.Forms.Form Public Sub New() MyBase.New() InitializeComponent() End Sub Private components As System.ComponentModel.IContainer Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.TextBox1.Location = New System.Drawing.Point(80, 16) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Text = "TextBox1" Me.ClientSize = New System.Drawing.Size(624, 502) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1}) Me.Name = "Form1" Me.Text = "Form1" End Sub End Class Public Class Form2 Inherits Form1 Public Sub New() MyBase.New() InitializeComponent() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click MsgBox(Me.TextBox1.Text) End Sub End Class Quote --tim
Cywizz Posted February 4, 2003 Posted February 4, 2003 (edited) I think I see Vidya's problem : .. Dim ins As New InsertSalesRep() .. The above line creates a new instance of InsertSalesRep, meaning a new instance of the textbox 'address'. The value will never be the same as that of the 'address' text field on the base form (another instance on its own) I would use divil's suggestion but will pass a text value only, e.g. 'insert function in your derived form Public Sub insert(value as String) MsgBox(value) ------> should now displays the value End Sub Hope it helps PS I just read the tread again and I guess thats what you meant in your reply divil... Edited February 4, 2003 by Cywizz Quote Howzit??
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.