By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,483 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,483 IT Pros & Developers. It's quick & easy.

how to declare static varible inside a class ?

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.