Jump to content
  • Advertisement
Sign in to follow this  
benryves

[.net] Calling a non-shared Sub from a Private class?

This topic is 5171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Yes, another one from me [sad] Let's say you set up a Private Class inside a form. You have a Sub on that form to redraw the title bar, fix up the status bar and so on that is called whenever something changes. The class inherits from a TextBox, and it changes the file status flag to "dirty" (a property of the Class) by handling the TextChanged property. However, if I try and call my updating sub I get an error - so I set the Sub to shared, and now the code inside the Sub won't work. Gah! How can I get around this? It claims it needs an object reference, but frmMain.updateStatusBar() won't work (and frmMain is the object, AFAIK...)

Share this post


Link to post
Share on other sites
Advertisement
The reference it is missing is not the reference to the form but to Me. Shared Functions don't have a Me so you cannot access instance properties of the class.

The proper way to set it up is to add a function to the form (public SetStatus(...)) and then call this function from within the SourceFile class. Like this:

Dim frm As Form = Me.FindForm()
Dim frmM as FrmMain
frmM = ctype(frm, frmM)
frmM.SetStatus(...)

Do learn the language and OO!! :)

Cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by ernow
Do learn the language and OO!! :)


I'm trying but am failing to find something that explains it decently. Don't say MSDN - I don't have an internet connection! The books I've looked at tend to go on and on in very abstract ways about the programming, but never actually show you how to implement things.
Thanks anyway!

Share this post


Link to post
Share on other sites
I know, I told you before :)

However questions like these find their roots in not knowing the basics of programming theories. As long as you do not read books about these abstract things you will keep on running into them. There can be no book that contains each specific problem. That is why you have to learn the abstracts. Pick up a book on Object Orientation and/or design. This can't hurt you and will make you design better. An other good one is "The pragmatic programmer" or "Refraction"

Cheers

Share this post


Link to post
Share on other sites
It's just that the majority of books I look at seem to have been translated from the Dutch by a Korean rice-husker. In short, they're pretty unreadable; I just want something that explains things in a clear manner, and doesn't dress things up weirdly. Bah. It's my fault, I guess.

Share this post


Link to post
Share on other sites
Ok, in that case try an English one... I never read programming books in Dutch, I always go with the native language of the book. Many translators have no clue whatsoever about the subjects being explained. Also: only the popular (read: no so good books) will get translated into Dutch. The goodones (read: for a tiny audience) never get translated.

Hmmm... perhaps I should write a Dutch one if there is a need. I always figured I should write in English but then again...

I can recommend: The Object Primer: The Application Developer's Guide to Object-orientation and the UML by Ambler

Zet 'em op!

Share this post


Link to post
Share on other sites
Sorry; I didn't mean they were in Dutch, but that the books appear to have been translated from Dutch to English by a Korean rice-husker. In short, they make no sense to me whatsoever [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!