Object Reference

binderben

Member
Joined
Sep 22, 2005
Messages
7
Programming Experience
Beginner
Hi Everyone, I hope I am asking this question in the right place...

I am in the middle of a tutorial and I am up to a part
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

GameClass.Paint(e)

End Sub


The error I am getting is:

Error 3 Reference to a non-shared member requires an object reference.

I think it is a pretty easy thing fix I am just pretty Noob at this

Thank You :)
 
you are calling a gameclass.paint(e) without initializing the object. In other words, a class must must have an instance before its members are called (keyword: new).
You can initialize a class as
gameclass = new gameclass(...)

then call gameclass member in the paint eventhandler

or make a method gameclass.paint(e) "shared" on its definition

public shared sub/function paint(e as whateverdatatype)

end sub/function
 
No.... I don't think that's the problem.... that generates a different (but similar) kind of error.

It's the "Handles MyBase.Paint" that has me curious.... Did you put that in, or did the IDE? Because I don't think that's right. It should be "Handles Form1.Paint"

-tg
 
TechGnome said:
No.... I don't think that's the problem.... that generates a different (but similar) kind of error.

It's the "Handles MyBase.Paint" that has me curious.... Did you put that in, or did the IDE? Because I don't think that's right. It should be "Handles Form1.Paint"



I dont think he can handle form1.paint event on the same class that form1 is defined. A window form usually handles Mybase.paint event. As a matter of fact, IDE generates error if you try to handle the form1.event instead of mybase.event
"Handles clause requires a WithEvents variable".


Iam using VS.Net 2003; techGnome, what IDE are you using ?
 
2003.... I'm not saying it was wrong.... just that it looked wrong, because it's not the base that's actualy being painted... but the current instance. But if that's what the IDE put there, then it *should* be correct.

But after looking things over again, I see what you mean. The Paint method isn't shared, so it needs to be part of an instanciated object, hence the error, yeah, I get it now.... just took me a while.

-tg
 
Back
Top