|
-
Feb 7th, 2012, 11:05 AM
#1
Thread Starter
New Member
Classes advice
Hey guys
I'm just wondering, how do i make a class link into my main code, it is in the same project so no need to reference it
ive set up the the class and typed
dim X as new XY
X(being name of variable, XY being the name of the new class)
but they aren't linking/ working
many thanks
R.vb
Last edited by richardMorris.vb; Feb 7th, 2012 at 12:34 PM.
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 11:20 AM
#2
Re: Classes advice
What is not working? Dim is used at a local level, if you want it available to the whole form/module, you have to declare it at the top Private x as New Xy.
-
Feb 7th, 2012, 12:27 PM
#3
Re: Classes advice
is the class in the same project? Or did you put it into another project? If it's in another project, then you need to reference it first. If it's in the same project, then you may need to provide some actual code, not some theoretical code...
-tg
-
Feb 7th, 2012, 12:33 PM
#4
Thread Starter
New Member
Re: Classes advice
tg thanks for the help.....
grimfort thank you very much that's just what i needed so to call a class instead of dim i use private in its place?
thank you
R.Vb
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 12:58 PM
#5
Re: Classes advice
No, not quite. Dim is the same as Private in almost every case. Normally, variables that are declared outside of any method are declared with Private, Protected, Friend or Public. You can also declare them with Dim, which acts the same as declaring them as Private. Dim is most commonly used for declaring variables that are declared inside of methods.
From your initial post, it wasn't clear where you were declaring that variable X. The use of Dim suggests that you were declaring it inside of a method, in which case it will not be visible to any code outside of the method. The syntax of the variable declaration was fine, and would work. Where that variable is visible is determined by the scoping rules, and that is probably where your problem lies. That's what TG was getting at. The variable is there, it is properly declared and properly instantiated, but that doesn't mean it is visible just anywhere. If it is declared that way outside of any method (at class scope), then it will only be visible to other methods inside the same class. If it is declared that way inside a method, then it will only be visible inside that method.
My usual boring signature: Nothing
 
-
Feb 7th, 2012, 01:04 PM
#6
Thread Starter
New Member
Re: Classes advice
hey thanks for the insight it was very helpful 
i've put the class it self as Private,
it was to make a savefiledialog box, i have it working in the main project,
but want to put it in a class to make it look neater and easier on the eyes
many thanks
R.Vb
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 01:07 PM
#7
Re: Classes advice
It is rare to have a class be Private, though it is entirely possible. Normally that is done when the class is defined inside another class, something like this:
Code:
Public Class Outer
'Stuff for the outer class
Private Class Inner
'Stuff for the inner class
End Class
End Class
In such a case, the Inner class can only ever be created or used within Outer. This greatly limits the versatility and usefulness of Inner, which is why it is rarely done.
My usual boring signature: Nothing
 
-
Feb 7th, 2012, 01:38 PM
#8
Thread Starter
New Member
Re: Classes advice
so should i leave the class as public?
then after the class call upon it via the private function?
Thank you for the help
R.Vb
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 01:41 PM
#9
Re: Classes advice
I don't think there is an answer for that. You can't call a private function of a class from outside the class, regardless of whether the class itself is public or private. If you have a private function outside the class, it doesn't matter whether the class itself is public or private. So, I'd say that at this point we are just talking in generalities, but that's about it, and having said that, I'm going to disappear for a day or three.
My usual boring signature: Nothing
 
-
Feb 7th, 2012, 01:46 PM
#10
Thread Starter
New Member
Re: Classes advice
thanks for the help,
have fun hiking 
R.Vb
A programmer in need, is a programmer in deed
-
Feb 7th, 2012, 07:06 PM
#11
Re: Classes advice
 Originally Posted by Shaggy Hiker
In such a case, the Inner class can only ever be created or used within Outer. This greatly limits the versatility and usefulness of Inner, which is why it is rarely done.
But is precisely the reason that it is done when it is.
I had a need for a private inner class just the other day, in fact. I needed to allow non-UI elements to take part in our UI contextualising system (disabling certain controls when the function they control is not available due to application state). I wrote a contextualisation controller that worked against a new Interface I devised rather than against UI controls.
The implementation of that interface would be specific to each of the non-UI classes that I wanted to interact with. Furthermore, the implementation would need to access internal state of the class instances that I did not want to expose. Implementing the interface directly on the class was not desirable because the class did not need that extra responsibility, so I defined a private nested class that implemented the interface, had each instance of the outer class create an instance passing in a reference to itself so the inner class could control it, then had the outer class expose a read-only property typed as the interface that returned the instance of the private class. Wow, it sounds convoluted when I write it like that, but in code it was an elegant solution to the problem.
-
Feb 8th, 2012, 01:18 PM
#12
Thread Starter
New Member
Re: Classes advice
hey evil giraffe.... i have no idea what you just said!!! haha
but thanks for commenting
A programmer in need, is a programmer in deed
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|