[Gambas-user] Value is not static

Bruce Steers 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

Try this...
 ' 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 CalcValue
  Else
    Print "An error Occurred"
  Endif
End

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.

BruceS

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
> Catch
>   Return False
> End
>  - - - - -
>  ' 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
>   Else
>     Print "An error Occurred"
>   Endif
> End
>  - - - -
> 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...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210616/5e2849d4/attachment.htm>


More information about the User mailing list