Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Accesing Another Class Methods

 

Yooo, Super-askingdude here!

 

Is there a way to access Class methods and variables without using the Shared statement or the New statement? Here's my code:

 

Public Class BigClassy
   Public vPublicVariable As Integer

   Public MyStructy As Structy     ' I'm not sure if I have to use NEW here
End Class

Public Structure Structy
   ' Creating something like "Public BC as new BigClassy" here will do?
   Public Sub FindBigClassyVariable()
       BigClassy.vPublicVariable = 100     ' This returns an error of course
   End Sub
End Structure

 

Do I have to create a new instance of BigClassy within Structy to access the current value of vPublicVariable? (because I assume that doing so will erase it)

 

This is like melting my brain... I don't know how to achieve my goal here.

Well, I hope someone will help me!

Love!

Edited by Doggo120
  • Administrators
Posted

Re: Accesing Another Class Methods

 

If you are creating a class member without the shared keyword then that member is associated with an instance of a class - this means you would need to declare a variable and assign an instance of the class to this variable and access the member via this variable.

 

If it is marked as shared then it is associated with the class rather than an instance and only one copy would ever exist in memory - this is accessed via the class as opposed to an instance.

 

In practice though you would normally be looking at instances rather than shared members unless you have a good reason to use shared. It might help if you gave a little more detail about what you are trying to do and see if anyone can give you more specific advice.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...