Discussion:
Static variable
(too old to reply)
S?ren Olesen
2003-11-11 10:42:57 UTC
Permalink
Hi

I'm a newbie to VB and would like to know if the foloowing is
possible:

I'd like to create a "static" variable, which holds the same value
across instances of the same class, but not derived classes

Ie. somethind like this

Public Class c1
Public Shared name As String
End Class

Public Class c2
Inherits c1
End Class


Private Sub test()

c1.name = "Class1"
c2.name = "Class2"

Dim myC1 As c1
myC1 = New c1

Dim myC2 As c2
myC2 = New c2

Dim str1 As String
Dim str2 As String

str1=myC1.name
str2=myC2.name

End Sub


However I'd like str1 to have the value "Class1" and str2 the value
"Class2".... but how to I do that ??

TIA

SMO.
Ryan
2003-11-19 18:31:46 UTC
Permalink
To create a static variable, use this method. Inside each class do the
following:

static variable as string 'for example

This will create a static variable.
Post by S?ren Olesen
Hi
I'm a newbie to VB and would like to know if the foloowing is
I'd like to create a "static" variable, which holds the same value
across instances of the same class, but not derived classes
Ie. somethind like this
Public Class c1
Public Shared name As String
End Class
Public Class c2
Inherits c1
End Class
Private Sub test()
c1.name = "Class1"
c2.name = "Class2"
Dim myC1 As c1
myC1 = New c1
Dim myC2 As c2
myC2 = New c2
Dim str1 As String
Dim str2 As String
str1=myC1.name
str2=myC2.name
End Sub
However I'd like str1 to have the value "Class1" and str2 the value
"Class2".... but how to I do that ??
TIA
SMO.
Loading...