Unable To Use An Instance Of The Nested Class Through A Public Variable Of The Parent Class?

Jun 7, 2012

I want to created a nested class that can only be visible to and instantiated from the parent class.But I also want to be able to use an instance of the nested class through a public variable of the parent class.I tried making the nested class private, or making the nested class' constructor private, but it won't compile.Is it possible to do this in .NET?

[Code]...

View 3 Replies


ADVERTISEMENT

.net - Visual Studio Setting: Invoke Directly Sub/nested Class (omit Parent Class)?

Feb 5, 2011

E.g. I have a class:

Namespace Common
Public Class AClass
Public Class BClass

[code]....

How can I use BClass without saying AClass.BClass, I've see some existing code using this format, but I can't find the setting.

View 1 Replies

Get A Value Inside Parent Class From Child Class (in Nested Classes)?

Jan 1, 2012

I have Class1 and class2 which is inside class1, VB.NET code:

Public Class class1
Public varisbleX As Integer = 1
Public Class class2

[code]....

View 1 Replies

Way To Make A Value Accessible Only To Parent Of A Nested Class

Jun 24, 2009

In general, according to the OOP paradigm, my understanding of encapsulation basically says:

-If a member is private, it can only be accessed by the class.
-If a member is protected, it can only be accessed by the base class and any derived classes.
-If a member is public, it can be accessed by anyone.

If I have a nested class, can I declare a property to be accessible only to that class and the parent class it's nested within? For example:[code]In the example, I cannot directly access myNestedObject.myInt or myNestedObject.myDbl from an instance of ContainerClass if those members are Private or Protected. But suppose I don't want to make them Public,because then they are TOO exposed: they can be altered from anywhere, not just within a Container Class object. Declaring them Friend would still be too weak as that would allow them to be altered from anywhere within the application.

View 2 Replies

Class Property Usage - Unable To Retrieve A Variable From On Class

Nov 14, 2009

I have three class files, accounts.vb and transactions.vb in addition to my form.vb. I am unable to retrieve a member variable from on class from inside the other. When the combobox index changes, the program loads the correct account (checking or saving) from two different sequential files. I don't think I have the calcBalance procedure in the correct class file. And that is what I am having trouble with. Accessing it to display it. [Code]

View 1 Replies

How To Make A Class Instance Public

Aug 21, 2011

Is there any way to make a class instance public?In my mainform I define an instance of a certain class and then later on in some other forms which appear I want to alter this class.I try and pass them through when creating new instances of these other forms and it tells me Error3<instance of the class I want> cannot expose type <the class> outside the project through class <the form I want to edit it with>Which I gather from documentation is about it defeating the purpose to have a private class suddenly be thrown aroudn.but then how do I make it public? I can't define it in the first place as public myXClass as XClass, it only accepts private.

View 6 Replies

Make Constructor Public And Allow Anybody To Create An Instance Of Class?

Apr 6, 2009

I have a class inside a class.I need to expose the properties of the 2nd class to other classes, therefore it is public.However, I do not wish other classes to be able to create instances of this 2nd class, it should only be instantitated from its parent class.I thought I could resolve this issue by making the constructor of the 2nd class private, but this even prevents the parent class from instantiating its child class! How can I work around this, do I have to make the constructor public and allow anybody to create an instance of the class?

View 3 Replies

.net - Using A Class Like A Public Variable In Asp.net?

Apr 13, 2009

I'm getting an error in .net when trying to declare a Public class on my code behind page.

Partial Class _Default Inherits System.Web.UI.Page

Public someVariable as integer
Public someClass as className

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load [...]

The error I'm getting is BC30508: 'someClass' cannot expose type 'className' in namespace '<Default>' through class '_Default'.The goal here is accessing the class properties in script blocks on the aspx page like this <%=someClass.classProperty%>

I'm not sure if I'm trying the right methods (I've tried several ways of declaring the public class) or if it can even be done..

View 3 Replies

Class C Inherits Class D Is Class D A Superclass Or Parent Of Class C?

Dec 16, 2009

If Class X is within the scope of Class Y, is X a subclass of Y?If Class A is a sub Class of B, then is Class B considered a super class of A?if Class C inherits Class D is Class D a superclass or parent of Class C?if Class E extends Class F then we can consider Class E a child of F?if Class G inherits Class H and is within the scope of Class I then who is the parent of Class G? Classes that inherits Class J and classes that are within Class J are all sub classes of Class J?

View 1 Replies

How To Call Variable In Public Class

Aug 22, 2011

I have this public class
Public Class commonSettings
Dim etcString As String = "some string"
End Class
How can I call etc String and use it entirely on my code?

View 3 Replies

Accessing A Public Shared Variable From A Different Class?

Jan 10, 2012

I currently have two forms, and I need to share the value of a variable in one of them.

I declared the variable to be 'Public Shared', and assigned a value to it. However,

when I inspect the value it appears as 'Nothing'. Here is the snippet:

Public Class A
Public Shared sVar As String = Nothing
Private Sub A_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]....

View 4 Replies

Set The Value Of A Public Class Variable To A Text Box Entry?

Apr 1, 2010

how to set the value of a Public Class variable to a text box entry?

I have a variable declared in the Public Class that was assigned to a public variable and I want to be able to have user entry via textbox.

If i change the variable to an integer and set it to textbox my program wont build.

View 1 Replies

Accessing Instance Of A Class Through A Variable?

Nov 12, 2010

i have

VariableA as Class1
Variable1 as string
Variable1 = "VariableA"

I want to be able to use Variable1 to get access to VariableA(?).

So i want to able to do something like

VariableA.Property1 = "test"
But like this:
Variable1.Property1 = "test"

View 5 Replies

Iterate Through A Class With Nested Class Of Unknown Type?

Feb 15, 2011

I have a class that hosts inside other classes that can host otherclases as well and so on.

I want to change the value of one property (PropertyA) in all classes down the tree.

How can i do that when i dont know the the type of class inside?

How can i iterate through the classes hostes as proeprty of the mother class?

I am trying to use reflection but i get just the properties of the first class

View 1 Replies

Check If Variable Holds An Instance Of Class?

Apr 10, 2011

Dim myObject As Something There I defined my variable myObject of type Something. But, as you can see, I am giving it no value yet. Sometime on runtime I want to check if myObject is holding a value or not. I tried this: If myObject <> Nothing Then But apparently I can't do such comparison.

View 3 Replies

Class-level Static Variable Per Instance?

Jan 28, 2010

I need a static variable to get a ListItemCollection from a List control (I can do this, but if I don't set it as Shared It's not preserving the values as it should). The thing is that this class is a SharePoint webpart, so I most probably will be using the webpart more than once, and I need this variable to be unique to each webpart, which shared doesn't accomplish.I tried everything you can imagine. I placed a Static variable within a Sub (shared and not shared), I tried it with Properties (also Shared and not shared)...

View 3 Replies

Can't Make Difference Between Public Class And Private Class And Friend And Protected Friend Class

May 15, 2009

I can't make difference between public class and private class and friend and protected friend class.

View 1 Replies

.net - Create A Variable Of An Instance Object Of A Class At Runtime?

Sep 29, 2011

I am trying to create new variables inside a class after creating its object at runtime. The problem is that I don't know the variable names or the value beforehand so I have to create the new variables at runtime.

[Code]...

This is a more elaborate explanation of my code. If you observe that in the Eval function I have tried to evaluate Fval(abc). Now the object array abc is not declared in the Test class because it existence is not known beforehand. What I want to do is create an object array abc of length 2 and populate it with some values and when Fval(abc) is called then then the value of index 1 should be the return value of Eval fucntion.

View 2 Replies

.NET : Runtime Is Initializing A Variable To An Instance Of The Wrong Class?

Jul 26, 2010

I've got some code that looks like this:

If ediFileGroupAbbr = "NIPDSINV" OrElse ediFileGroupAbbr = "WWPDSINV" Then
Dim p As New PrivateBillingAdapter_ForN(ediFileGroupAbbr, businessLocationID, mode, EDIJobItemLogID, BusinessUnitID)
Return p.ProcessEDI(True, False)
ElseIf ediFileGroupAbbr = "FOPDSINV" Then

[code]...

to which I'm passing in a value of ediFileGroupAbbr = "FOPDSINV". But the code is executing as if it's dropping into the third condition (p is a PrivateBillingAdapter). So I've stepped into the code and, sure enough, it drops into the second condition. BUT, if I step into the execution of the constructor, the debugger jumps to an odd place in the code - sort of the middle of a method and not on any actual line of code.A couple clicks and it hops back out of the constructor, still in the second block of code. But if I mouse over the variable p to see it's type, boom, its a PrivateBillingAdapter (from the third block).Like I said, something is clearly wrong but I don't know what. I've tried rebuilding several times but with no new results.This is VS2003, framework 1.1 with VB.NET.

View 1 Replies

C# - .NET Generic Class Instance - Passing A Variable Data Type

Jun 2, 2010

I'm tyring to pass a variable data type to a template class. Something like this:

frmExample = New LookupForm(Of Models.MyClass) 'Works fine

Dim SelectedType As Type = InstanceOfMyClass.GetType() 'Works fine
frmExample = New LookupForm(Of SelectedType) 'Ba-bow!
frmExample = New LookupForm(Of InstanceOfMyClass.GetType()) 'Ba-bow!

[Code].....

I'm assuming it's something to do with the template being processed at compile time but even if I'm off the mark there, it wouldn't solve my problem anyway. I can't find any relevant information on using Reflection to instance template classes either.

(How) can I create an instance of a dynamically typed repository at runtime?

View 4 Replies

VS 2008 Reference Parent Class From Inside Child Class?

Apr 11, 2009

I have a 'property management class' that contains several functions and properties. I have several other classes that use the 'management class' as a property to derive the value of several of its other properties.Is there a way for me to reference the outer class from the 'management class' functions without having to pass it as a parameter? I ask because several different classes can have this 'management class' as a property and am having a hard time typing the parameter.

View 7 Replies

Access Members Of A Sub Class Through A Property Of The Parent Class?

Mar 30, 2010

This is a bit of a continuation from a previous post for which AtmaWeapon was very informative.

Problem:
A parent class has a sub class with various properties. A property of the parent class is a List(of T) with T = the sub class The issue is how to store data in the sub class of the instantiated parent

Some example code (hopefully formatted correctly):

Code:
'=========== Class Definitions =============
Public Class courseClass
Public Class timeTableClass

[Code].....

View 7 Replies

Reference A Parent Class Object From A Child Class?

Jan 2, 2010

I have a Parent Class Called Fuselage that containsfour child classes called Forebody, CenterBody, AftBody, and CrossSection. CrossSection classcontains objects common to Forebody, CenterBody, and Aftbody (example: width). How do I access thewidth property in CrossSection from within the classForebody?

Public Class Fuselage
Dim Forebody As ClsSection
Dim Centerbody As ClsSection

[code].....

View 6 Replies

Declare An Internal Class Within A Public Class?

Nov 17, 2008

how to declare an internal class within a public class using vb.net?

View 2 Replies

Private And Public Class At Class Library

Mar 12, 2011

I'm posting this there is a relationship with my previous post [URL]

I have two projects, namely:

1. Project1 (Windows Application)

2. Project2 (Class Library)

in Project2 there are several classes:

* frmLogin.vb
* frmCustomer.vb
* clsGlobals.vb

in my case, I want to frmLogin.vb and frmCustomer.vb not called in Project1 and I can only call is clsGlobals.vb

View 8 Replies

VS 2010 Converting Public Class To Class With Get And Set?

Nov 30, 2011

I need to convert the following code, so that it exists as a created class "Payroll" that utilizes "Get" and "Set" elements. Unfortunately, I'm completely lost.

Public Class frmPayroll
Private Sub frmPayroll_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code].....

View 2 Replies

How To Assign A Different Reference To A Class Instance From Inside The Class Code

Jan 18, 2011

my proble is the following: I have a class MyClass and another class Modifier, which has a method ModifyMyClass(ByRef mc as MyClass) that receives a MyClass instance as ByRef parameter to modify it. A smell of the code is:

[Code]...

View 4 Replies

Class With Class Properties: AObject Reference Not Set To An Instance?

Aug 19, 2009

I have a class in which some of the fields are also classes.I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"But the code compiles fine.

dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error

How can i fix this ?

View 6 Replies

Class With Class Properties: Object Reference Not Set To An Instance

Aug 19, 2009

I have a class in which some of the fields are also classes.

I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"

But the code compiles fine.

dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition
dados_Defenicao.arCode = "123"
dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error

View 4 Replies

Declare A RANDOM Class Instance At CLASS Level?

May 6, 2010

If you run this code you will see that the 500 PictureBoxes that are added ( this is easier to show than adding pixels as a pixel is only a single point ) fall mainly on the diagonal.With regard the RANDOM class, why should this be like this when the bounds of the instances are? >>

p.Location = New Point(x.Next(0, Me.Width + 1
), y.Next(0, Me.Height + 1 ))
as in this code.>>

[code].....-2138214fdeb4

View 9 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved