Sample Project

Excuse me. I am a new vb programming and my enlish is not well. A link on top is my sample project. I have to try hard to fix it. But i have no idea how to fix. If you download my project and run it. When you press button TEST you will see the error. Please help me and expand me how to fix. I use visual studio 2010 to create project.

Edited 4 Years Ago by winki: chenge link title and add more details

Attachments error.png 50.42 KB

Just going by the error on the screenshot, the IDE has told you the problem, are you sure you have initialised CurrentControl?
Are you initialising after you try to use it?

Edited 4 Years Ago by Akill10

First of all, you are calling a procedure that does not exist.

From what I see, TestMessage is not a member of the property.

Just going by the error on the screenshot, the IDE has told you the problem, are you sure you have initialised CurrentControl?
Are you initialising after you try to use it?

I'm apologize. I'm a beginner, I don't know how to initialised, initialising. I really try to think how to code it. but i fail. make me sense, please.

error21

error41

This is sub TestMessage

Edited 4 Years Ago by winki: add picture

Can you post the code that causes problems in here?
thx in advance.

Picture above your post. That's my problems.

Now, I still can't fix this error. I'm waiting for someone can teach me how fix this.

I see you have declared it as an overide, but do not see the declared sub that is overridden

I think i already do that.

 Public Class TutorialControlBase
      Private _parent As FrmMain = Nothing

      Public Sub New()
                InitializeComponent()
                SetStyle(ControlStyles.SupportsTransparentBackColor, True)
      End Sub

      Public Property ParentFormMain() As FrmMain
                Get
                          Return _parent
                End Get
                Set(ByVal value As FrmMain)
                          If (Not Object.Equals(_parent, Nothing)) Then
                                    Return
                          End If
                          _parent = value
                End Set
      End Property
      Public ReadOnly Property RegisterControl() As RegisterControl
                Get
                          If (Not Object.Equals(_parent, Nothing)) Then
                                    Return _parent.RegisterControl
                          End If
                          Return Nothing
                End Get
      End Property
 End Class



 Public Class TutorialControl
      Inherits TutorialControlBase

      Public Sub New()
      End Sub
      Public Sub SetParent(ByVal parent As Form)
                If Me.ParentFormMain Is parent Then
                          Return
                End If
                Me.ParentFormMain = TryCast(parent, FrmMain)
      End Sub
      Friend Overridable Sub TestMessage()
      End Sub
 End Class
 Public Class GridTutorialControl
      Inherits TutorialControl

      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                MyBase.Dispose(disposing)
      End Sub
 End Class


 Public Class GridForm
      Inherits GridTutorialControl
      Private WithEvents TextBox1 As System.Windows.Forms.TextBox
      Private components As System.ComponentModel.IContainer = Nothing

      Public Sub New()
                InitializeComponent()
      End Sub
      Protected Overrides Sub Dispose(ByVal disposing As Boolean)
                If disposing AndAlso ((Not Object.Equals(components, Nothing))) Then
                          components.Dispose()
                End If
                MyBase.Dispose(disposing)
      End Sub
      Private Sub InitializeComponent()
                Me.TextBox1 = New System.Windows.Forms.TextBox()
                Me.SuspendLayout()
                '
                'TextBox1
                '
                Me.TextBox1.Location = New System.Drawing.Point(12, 12)
                Me.TextBox1.Name = "TextBox1"
                Me.TextBox1.Size = New System.Drawing.Size(505, 20)
                Me.TextBox1.TabIndex = 0
                '
                'GridForm
                '
                Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
                Me.ClientSize = New System.Drawing.Size(529, 382)
                Me.Controls.Add(Me.TextBox1)
                Me.Name = "GridForm"
                Me.ResumeLayout(False)
                Me.PerformLayout()
      End Sub
      Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
                MyBase.OnLoad(e)

      End Sub

      Friend Overrides Sub TestMessage()
                MyBase.TestMessage()
                TextBox1.Text = "TESTED OK"
      End Sub
 End Class

It may just be as simple as delcaring a new instance of the propery.

Like so:

 Dim cont As New TutorialControl
 cont.TestMessage()

^_^ your simple. I've tried it. but not work it can't call Overrides Sub in GridForm it can call just Overridable Sub in TutorialControl

Edited 4 Years Ago by winki

I have another possible suggestion.

You can wrap it in a try catch, and then throw the stack trace.

Example:

Try
    'Place code here.'
Catch ex As Exception
    MsgBox(ex.StackTrace.ToString)
End Try

Then screen cap and paste here?

Thanks,
Begginnerdev

Untitled4

Try
    CurrentControl.TestMessage()
Catch ex As Exception
    MessageBox.Show(ex.StackTrace.ToString)
End Try

........ ^_^ ........

Error Message : at WindowsApplication1.RegisterControl.AnonyMouseMethod(Object sender, EventArgs e) in C:\User\Apple\Desktop\WindowApplication1\Windowapplication1\Register.vb:line 14

Edited 4 Years Ago by winki: add details

Sorry, I was unable to recreate your problem. I can't download your project due to usage policies. I am still trying to think of what possibly could be wrong.

I was able to fix your problem by doing the following:

    Dim gf As New GridForm
    gf.TestMessage()

This takes away the Nullreference exception, but does not post "Tested OK" in your text box.

I see you are using a poperty to assign the values:

   Public Property CurrentControl As TutorialControl
                Get
                          Return fcurrentcontrol
                End Get
                Set(ByVal value As TutorialControl)
                          If fcurrentcontrol Is value Then
                                    Return
                          End If
                          fcurrentcontrol = value
                End Set
   End Property

But I do not see where you are assigning it any values.

Edited 4 Years Ago by Begginnerdev

I keep noticing that when the test message is called, it is calling this sub:

Friend Overridable Sub TestMessage()
End Sub

And not the override.

That is with changing this:

  Private fcurrentcontrol As TutorialControl

To this:

  Private fcurrentcontrol As New TutorialControl

And using your code:

 CurrentControl.TestMessage()

Edited 4 Years Ago by Begginnerdev

Just a thought. In your original post the error was on the line that said

CurrentControl.TestMessage()

Because CurrentControl is there as access to fcurrentcontrol, why not just replace the offending line with

fcurrentcontrol.TestMessage()

Edited 4 Years Ago by Reverend Jim

This article has been dead for over six months. Start a new discussion instead.