473,372 Members | 1,049 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,372 software developers and data experts.

how to declare static varible inside a class ?

how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks
Nov 20 '05 #1
6 30530
do you mean "shared"?

Public Shared ABS as Integer

also

Public Shared function doSomething() as System.Int32
End Sub
"The8thSense" <th*********@yahoo.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks

Nov 20 '05 #2
The8thSense,
As Rahul suggested. You would use the Shared keyword in VB.NET where you
would use the static keyword in C# or C++.

Hope this helps
Jay

"The8thSense" <th*********@yahoo.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks

Nov 20 '05 #3
thx :-)
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> bl
news:%2****************@TK2MSFTNGP11.phx.gbl g...
The8thSense,
As Rahul suggested. You would use the Shared keyword in VB.NET where you
would use the static keyword in C# or C++.

Hope this helps
Jay

"The8thSense" <th*********@yahoo.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks


Nov 20 '05 #4
Hi Jay,

I am under the belief that "Static"(in Visual Basic) can be used for local
instance level variable: whereas Shared is a class level variable.

Hence Static and Shared are different. The help of static keyword shows the
following...

The Static keyword indicates that one or more declared variables are static.
Static variables remain in existence and retain their latest values after
termination of the procedure in which they are declared.

The Static keyword is used in this context:

IS something wrong with my understanding??

You can declare a local static variable using the following syntax:

Static Dim x as Integer = 1

The value of x is retained even after the termination of the procedure.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
The8thSense,
As Rahul suggested. You would use the Shared keyword in VB.NET where you
would use the static keyword in C# or C++.

Hope this helps
Jay

"The8thSense" <th*********@yahoo.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks


Nov 20 '05 #5
Srinivas,
IS something wrong with my understanding?? There is nothing wrong with your understanding, nor in the statement I made!
:-|
Hence Static and Shared are different. The help of static keyword shows the following... You are correct Static & Shared in VB.NET are different, however I stated
that static in C# is the same as Shared in VB.NET.

C# has no equivalent to the VB.NET Static keyword.

Hope this helps
Jay

"Srinivas Kotipalli" <sr*******@sbcglobal.net> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl... Hi Jay,

I am under the belief that "Static"(in Visual Basic) can be used for local
instance level variable: whereas Shared is a class level variable.

Hence Static and Shared are different. The help of static keyword shows the following...

The Static keyword indicates that one or more declared variables are static. Static variables remain in existence and retain their latest values after
termination of the procedure in which they are declared.

The Static keyword is used in this context:

IS something wrong with my understanding??

You can declare a local static variable using the following syntax:

Static Dim x as Integer = 1

The value of x is retained even after the termination of the procedure.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
The8thSense,
As Rahul suggested. You would use the Shared keyword in VB.NET where you
would use the static keyword in C# or C++.

Hope this helps
Jay

"The8thSense" <th*********@yahoo.com> wrote in message
news:uZ**************@tk2msftngp13.phx.gbl...
how to declare static varible and static method inside a class ?
i try
"public static ABC as integer = 10"
and it said my declaration is invalid

Thanks



Nov 20 '05 #6
Hi The8thSense,

What are these variables of yours used for?

'Shared' means that they will be the same for all instances of the class.
Is this what you wanted?

'Static' within a local procedure is static in the traditional VB sense -
persistent value but limited scope.

Sub Foo
Static N As Integer = 1
MsgBox (N) '1, 2, 3...
N +=1
End Sub

And finally, if
public static ABC as integer = 10
is unchanging, then
public Const ABC as integer = 10
would perhaps be more appropriate.

Regards,
Fergus

ps What's the 7th sense?
Nov 20 '05 #7

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

Similar topics

7
by: lallous | last post by:
Hello, Why is the static variable inside a member function static for all instances and not static for the current instance of the object? -- Elias
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
1
by: Andrew Parker | last post by:
Hi, I'm having a syntax problem and hours of googling has yet to reveal a solution. I'm writing a class that contains only public static methods. It's a class of useful misc. functions that don't...
7
by: Action | last post by:
in c++ if i put static int count = 0; in a method; count can only accessed inside the method and retain it's value. is there equilvant thing in C#? thx
1
by: phoenix | last post by:
Hello, I guess I'm missing to logic behind the limitation or I'm doing something wrong (most likely). I have the following interface and class public interface IRBSPParser { void Parser(byte...
5
by: John Goche | last post by:
Hello, I would like to know whethere there is a difference between a const variable and a static const variable inside a class. After all, if a variable is const in a class, the compiler can...
7
by: beginner | last post by:
Hi Everyone, I have encountered a small problems. How to call module functions inside class instance functions? For example, calling func1 in func2 resulted in a compiling error. "my module...
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
1
by: kiran280603 | last post by:
hi i have a class in which i have a structure.. how to initialize a static variable "var" Class A { struct start { static int var; };
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.