Home > def > class 
 en fr de es it nl pl pt pt_BR mk sq hu cs tr ar fa id vi ko ja ru zh zh_TW eo
Previous  Next  Edit  Rename  Undo  Search  Administration  
Documentation  
Warning! This page is not translated.  See english version 
class
A class is a special Gambas object that describes the common features of objects having the same type.

Example of declaration and usage of an own defined class

Create a New Console project Add a Class (its name will be Class1) Then from the SUB Main create two instances of that Class1

See: You have all the Variables the twice: the same structure in each instance.

See: You need to create an instance using the NEW statement

The code example for the class

' GAMBAS class file
PUBLIC f AS Float
PUBLIC s AS String

PUBLIC SUB p()

Print "p is executed"
f = 4.5
s = "from call"
END

The code example for the MMain Module

' Gambas module file
PUBLIC xc AS Class1
PUBLIC yc AS Class1

PUBLIC SUB Main()
' Class1.s = "Class1 from main"     -> ERROR -> Class1 is not STATIC
xc = NEW Class1
yc = NEW Class1
yc.s = "yc from main"
xc.s = "xc from main"
xc.p()
PRINT xc, xc.f, xc.s
PRINT yc, yc.f, yc.s
' PRINT Class1.s                    -> ERROR -> Class1 is not STATIC
END

See also

Object Model