darknuke Posted January 12, 2004 Posted January 12, 2004 I'm trying to make a separate form to search a text box on Form1. I can call it from Form1, but not the find form. Find Form: Dim baseForm As Form1 ' I get "Object not set to an instance error when using this code" on executeion. If I try to declare baseForm as New, a startup error occurs baseForm.fileContents.Select(2, 2) Form1: ' Works like it should fileContents.Select(2, 2) Is there another way of doing this, or something I need to change? Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Leaders Iceplug Posted January 12, 2004 Leaders Posted January 12, 2004 Well, you need to at least set baseForm to a new instance of Form1. What startup error do you get? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
darknuke Posted January 12, 2004 Author Posted January 12, 2004 (edited) "An unhandled exception of type 'System.StackOverflowException' occurred in Text Editor.exe" Form1: #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() ' This line If I remove the declare on Form1 referring to the find form, it works fine, and vice versa. I'm guessing it's something simple I'm doing wrong :p . (This is a headache compared to how easy it was to do in VB 6.0 :( ) Edited January 12, 2004 by darknuke Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Administrators PlausiblyDamp Posted January 12, 2004 Administrators Posted January 12, 2004 What class does Form1 inherit from and what is in ir's Sub New? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 13, 2004 Author Posted January 13, 2004 Form1, and the standard InitializeComponent(). Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Leaders Iceplug Posted January 13, 2004 Leaders Posted January 13, 2004 MyBase.New() ' This line Does it work if you take ' that line out? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 Form1 inherits from Form1??? If so that is the problem - everytime you create a new form1 and call it's base constructor it's calling itself. shouldn't Form1 inherit from Form? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 13, 2004 Author Posted January 13, 2004 I'll just try to find some other solution, this isn't seeming to go anywhere :( . No, I must have misread your post, it does inherit Form. And when I remove that line, nothing. Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 Could you show us a bit more of the code in Form1 and the search form? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 13, 2004 Author Posted January 13, 2004 (I removed all Subs not associated to opening the find form.) Form1: Public Class editor 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 ' Loading of form data (removed, too long) Dim theForm As New findTextForm Private Sub findItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findItem.Click theForm.Show() End Sub End Class Find Form: Public Class findTextForm 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 textToFind As System.Windows.Forms.TextBox Friend WithEvents findText As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.textToFind = New System.Windows.Forms.TextBox Me.findText = New System.Windows.Forms.Button Me.Label1 = New System.Windows.Forms.Label Me.SuspendLayout() ' 'textToFind ' Me.textToFind.Location = New System.Drawing.Point(8, 8) Me.textToFind.Name = "textToFind" Me.textToFind.Size = New System.Drawing.Size(224, 20) Me.textToFind.TabIndex = 0 Me.textToFind.Text = "" ' 'findText ' Me.findText.Location = New System.Drawing.Point(248, 8) Me.findText.Name = "findText" Me.findText.Size = New System.Drawing.Size(72, 24) Me.findText.TabIndex = 1 Me.findText.Text = "Find" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(16, 48) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(192, 16) Me.Label1.TabIndex = 2 Me.Label1.Text = "(add search within selection option)" ' 'findTextForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(328, 77) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.findText) Me.Controls.Add(Me.textToFind) Me.Name = "findTextForm" Me.Text = " Find" Me.ResumeLayout(False) End Sub #End Region Dim baseForm As New Form1 Private Sub findText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findText.Click baseForm.fileContents.Select(2, 2) End Sub End Class Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Administrators PlausiblyDamp Posted January 13, 2004 Administrators Posted January 13, 2004 Where is Form1 declared? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 14, 2004 Author Posted January 14, 2004 Dim baseForm As New Form1 Private Sub findText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findText.Click baseForm.fileContents.Select(2, 2) End Sub In the find form. Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Administrators PlausiblyDamp Posted January 14, 2004 Administrators Posted January 14, 2004 How is Form1 declared? You posted the code for the findTextForm and editor but not Form1. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 14, 2004 Author Posted January 14, 2004 Look closer. :D I included both (just changed the name in other post). 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 ' Loading of form data (removed, too long) Dim theForm As New findTextForm Private Sub findItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles findItem.Click theForm.Show() End Sub End Class Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
Administrators PlausiblyDamp Posted January 14, 2004 Administrators Posted January 14, 2004 By the looks of it in the editor form you are declaring a new instance of findTextForm, but as part of findTextForm you are declaring a new instance of the editor form. Note the lines Dim theForm As New findTextForm and Dim baseForm As New Form1 (which i'm assuming is editor - correct?) if so each will create an instance of the other until you run out of stack space - hence the error you got. Does the findTextForm need to refer to the editor form? if so you should pass an instance of the editor to the findTextForm. in the findTextForm change Dim baseForm As New Form1 to Dim baseForm As Form1 and change it's sub new from ublic Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub to Public Sub New(f as Form1) MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call baseForm =f End Sub and finally in editor change ' Loading of form data (removed, too long) Dim theForm As New findTextForm to ' Loading of form data (removed, too long) Dim theForm As New findTextForm(me) and see if that helps. If i'm wrong about editor being form1 then adjust accordingly. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
darknuke Posted January 14, 2004 Author Posted January 14, 2004 Works, thanks for all the help! :) Quote This is only a test of the emergency broadcast system This is a product of hysterical mass confusion A ship of fools adrift on the sea of our pollution Rudderless and powerless on the sea of our delusion pennywise - this is only a test
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.