Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

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
Posted
Well, you need to at least set baseForm to a new instance of Form1. What startup error do you get?

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted (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 by darknuke

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

Posted
Form1, and the standard InitializeComponent().

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
Posted

MyBase.New() ' This line

Does it work if you take ' that line out?

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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.

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

Posted

(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

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

Posted

    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.

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

Posted

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

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
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
Works, thanks for all the help! :)

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

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