[Gambas-user] Value is not static
bsteers4 at gmail.com
Wed Jun 16 09:54:20 CEST 2021
error i see is...
you are naming your variable the same as the class "class1" maybe try *Dim
myClass as New Class1* or something
' Gambas module file
Public Sub Main()
Dim myClass As New Class1
Dim CalcValue As Integer
myClass.Value1 = 3
If myClass.ProcessIt() Then
CalcValue = myClass.Value2
Print "An error Occurred"
There using myClass.Value1 will access your defined instanced variable
using Class1.Value1 tries to access a static variable.
Static variables and functions are available through the class itself, non
static variables/functions are available through a defined instance of it.
think of a static variable as a global setting you can define for the class
at any time without creating a new object
non static as things you can set/use for each individual defined object.
On Wed, 16 Jun 2021 at 07:27, Ken King <kicking177 at gmail.com> wrote:
> If I have the following code
> - - - - -
> ' Gambas class file
> Public Value1 As Integer
> Public Value2 As Integer
> Public Function ProcessIt() As Boolean
> Value2 = Value1 * 2
> Return True
> Return False
> - - - - -
> ' Gambas module file
> Public Sub Main()
> Dim class1 As Class1
> Dim CalcValue As Integer
> class1 = New Class1
> class1.Value1 = 3
> If class1.ProcessIt() Then
> CalcValue = class1.Value2
> Print CalcValue
> Print "An error Occurred"
> - - - -
> it runs and works as I expect but if if I try to look at the class1
> values I get
> 'class1.Value1' is not static
> What am I not understanding?
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the User