Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Leaders
Posted

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....:(

--tim
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • Leaders
Posted
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?
--tim
  • Leaders
Posted
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.
--tim
Posted
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.
  • Leaders
Posted

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

--tim
Posted (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 by Cywizz
Howzit??

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...