472,126 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 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 30388
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> ¦b¶l¥ó
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by lallous | last post: by
7 posts views Thread by Drew McCormack | last post: by
1 post views Thread by Andrew Parker | last post: by
1 post views Thread by phoenix | last post: by
5 posts views Thread by John Goche | last post: by
37 posts views Thread by minkoo.seo | last post: by
reply views Thread by leo001 | last post: by

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.