Jump to content
Xtreme .Net Talk

merc208

Members
  • Posts

    6
  • Joined

  • Last visited

About merc208

  • Birthday 01/20/1969

Personal Information

  • Occupation
    Business Analyst Programmer
  • Visual Studio .NET Version
    2002
  • .NET Preferred Language
    Vb .NET

merc208's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Thanks!!!!!!!!!!!! Cheers guys!!! With a bit of swapping around I managed to get it to work. I appreciate your time and advice on this issue........ I think this VB6 -> .NET learning 'conversion' is gonna be a long uphill struggle!
  2. Yeah, sure..... I added your suggestion 'variable for variable' so now I've got this: Form1 Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 112) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(280, 20) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "TextBox1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Dim MyForm2 As New Form2(Me) Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged MyForm2.TextBox1.Text = TextBox1.Text End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create the second form MyForm2.Show() End Sub End Class Form2 Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Dim FirstForm As Form1 Public Sub New(ByVal f1 As Form1) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() FirstForm = f1 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 112) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(272, 20) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "TextBox1" ' 'Form2 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1}) Me.Name = "Form2" Me.Text = "Form2" Me.ResumeLayout(False) End Sub #End Region Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged FirstForm.TextBox1.Text = "TEST" End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class When I run it, It highlights the FirstForm.Textbox1.Text = "Test" and I get the strange error message (as in above posts) Thanks again
  3. OK... I understand that so far but when I've done that and then in to 'textchanged' event attached to the textbox on Form2 I put firstform.TextBox1.Text = "TEST" which I thought would then pass back the string to the textbox on form1 It still gives me..... An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication9.exe Additional information: Object reference not set to an instance of an object. Have I got some problem with my installation of .net?! Sorry, I know I'm being hard work today!
  4. Errors Thanks for that, but when I run it, it gives me As for the previous answer by Divil, would it be possible to give me some example code based upon my own?! Form1 Code Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 112) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(280, 20) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "TextBox1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Dim MyForm2 As New Form2() Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged MyForm2.TextBox1.Text = TextBox1.Text End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create the second form MyForm2.Show() End Sub End Class Form2 Code Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 112) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(272, 20) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "TextBox1" ' 'Form2 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1}) Me.Name = "Form2" Me.Text = "Form2" Me.ResumeLayout(False) End Sub #End Region Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class
  5. OK.... I've had a look around and I'm still stuffed! I've tried every combination of example I can find. This is my code.... Form1 is the startup form. It's creates a new instance of form two and allows the textbox on form2 to be altered to contain the text from the textbox on form1 Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Dim MyForm2 As New Form2() Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged MyForm2.TextBox1.Text = TextBox1.Text End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create the second form MyForm2.Show() End Sub End Class This works fine! Now on form two is where I am getting confused. I believe I need to pass a reference to Form1 before I am able to change the contents of the textbox on form1. So I create an instance (myForm1 as Form1????????), but when calling it later in the Textchanged event...... I get an error (An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication9.exe. Additional information: Object reference not set to an instance of an object.) I presume because it isn't a new instance.... but if I declare myForm1 as NEW Form1 it doesn't like it either!. Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Dim myForm1 As Form1 Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged myForm1.TextBox1.Text = TextBox1.Text End Sub End Class
  6. Hi Guys, I've read all the posts on this forum about this subject but am still totally in the dark. I have been a VB programmer for 8+ years and am really finding 'converting' to .NET difficult so any help would be greatly appreciated! The Problem: I went out and bought SAMS 'Teach Yourself VB.NET in 21 Days' as an 'easy' way to start learning .NET from scratch rather than just playing around with .NET. So far, so good! I'm getting an understanding of it all. The problem came on Day 4 when in the 'Exercises'. It asks to create two forms with Textboxes on each. When one textbox is updated on one form it was to replicate the text to the second. I managed to get it to create two forms, with the required textboxes and when the textbox on the base form (Form1) has text typed in it puts it in the textbox on form2. However what I can't seem to do is get it to change the text in the box on form1. I've tried creating a new object to point to form1 but it just errors.... and I am getting mad with it now! Can anyone out there please sooth my suffering just a little and give me some pointers?! Thanks in advance Sid
×
×
  • Create New...