Sign in to follow this  

VB question - quick answer needed.

This topic is 4689 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

i think you can if the varibale is in a modual, if not you just have to make it a pramater in the function your using(this is the way you supose to use objects anyway)

Share this post


Link to post
Share on other sites
what im tring to do here is access a sub outside of this class but in my form 1 class. VB.net says I need an object reference to do this. What is an object reference and how do i create one?

Share this post


Link to post
Share on other sites
in VB .Net, there are two sorts of methods - shared and not shared
Shared methods can be accessed through the type where they were defined, non shared require that you call them through a variable of that type (that holds and actual instance)

VB actually worked this way too, but it automatically defined default variables with the same name as Forms in your application - VB .Net will do this with the 2005 edition, but doesn't on 2002 or 2003.

What you need to do is have a variable that holds a form1 instance accessible from the code you want to call the method from - you can for example have a variable of type Form1 in a module, and on Form1's load event assign "Me" to that variable - you can then go and call non shared members through that variable:

Module Module1
Public Shared Var1 as Form1
End Module

'...
'on form1's load event:
Var1 = Me


'...
'On your code:
Var1.Show()

Share this post


Link to post
Share on other sites
Like I said I am new so I have no idea what you are doing.

here what I did.

Im creating a game for a school project due tommorow. It is a basic matching game where you flip over two tiles at a time to see if they match. to do this i set up a class holding the button object and some information about the tile and its click event. in the click event i need to acess some variables defined outside the class and a sub that will refresh the a couple labels on the form displaying the score and so forth. I need a simple way to be able to increase the score and call the refresh sub from the click event in this class.

Share this post


Link to post
Share on other sites

This topic is 4689 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this