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

Started by
6 comments, last by ernow 19 years, 7 months ago
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...)

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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!
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]

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

:)

I guessed as much, but couldn't resist...

Cheers

This topic is closed to new replies.

Advertisement