473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Use of class function

Hello,

I have a class named MyClass with 2 properties A and B and two
function Fa and Fb.

When I am using the class I am able to do the following:

Dim mc As MyClass
Dim s As String = mc.Fa

But I can't do:

Dim s As String = MyClass.Fa

Why?

Thanks,

Miguel

Sep 20 '07 #1
2 1106

You can only do the latter, if the variable is a static (shared in vb.net)
variable.

public class MyClass

public shared MyString as string = "ABC"

end class

something like that.


"shapper" <md*****@gmail.comwrote in message
news:11*********************@n39g2000hsh.googlegro ups.com...
Hello,

I have a class named MyClass with 2 properties A and B and two
function Fa and Fb.

When I am using the class I am able to do the following:

Dim mc As MyClass
Dim s As String = mc.Fa

But I can't do:

Dim s As String = MyClass.Fa

Why?

Thanks,

Miguel

Sep 20 '07 #2
Is Fa marked as shared? Any properties or functions you have defined on a
class are part of the object and can be accessed once you actually
instantiate a copy of the class. The only way to be able to access a
function without first instantiating a class is to mark it shared (or static
in C#). The downside of this, because this means you can access the function
without instantiating an object, you can't make use of anything within that
function that relies on the properties or variables of the class. So, if
MyClass.Fa was shared simply returned a pre-defined value or performed some
operation that didn't require the other parts of Fa that are not marked as
shared as well, then you can access it directly. If MyClass.Fa just returned
the results of 2 + 2 that could be workable (or accepted some parameters and
worked with those) but MyClass.Fa couldn't do something like add MyClass.A
and MyClass.B together since Fa isn't part of the instantiated object.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"shapper" <md*****@gmail.comwrote in message
news:11*********************@n39g2000hsh.googlegro ups.com...
Hello,

I have a class named MyClass with 2 properties A and B and two
function Fa and Fb.

When I am using the class I am able to do the following:

Dim mc As MyClass
Dim s As String = mc.Fa

But I can't do:

Dim s As String = MyClass.Fa

Why?

Thanks,

Miguel

Sep 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
3
by: Robert | last post by:
Python doesn't know the class of a method when container not direct class attribute: >>> class X: .... def f():pass .... g=f .... l= .... >>> X.g <unbound method X.f>
8
by: Nick | last post by:
I have the following code: var obj = {a:0, b:1, ...} function f() {...} obj.f = f // This will make a instance method? How to make a Class method for the class of obj? Or what's the...
9
by: mead | last post by:
What kind of classes is qualified as "concrete classes"? When should a member function in a class defined as "pure virtual" and when as "virtual"? Thanks!
2
by: dinks | last post by:
Hi, I'm new to C++ and have been assigned a task which i dont completely understand. Any help would be greately appreciated. Here is the problem: The class "linkedListType" use the "assert"...
9
by: baumann | last post by:
hi all, to implement a singleton class, one has define a static function in the singleton class, class A{ public: static A* getInstance() { static A a; return &a;
6
by: Ken Foster | last post by:
Is it possible to return a class (not an instance of a class) from a function? For example (actually tried this code, it didn't work, but it's what I want sort of): Class EventMessage Public...
4
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
5
by: Ben | last post by:
Hi, i defined a function in the base class 'ford' and the same function (with different output) in subclass "peugeot". I first put 'Overridable function' in the base class and 'Overrides...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.