[Gambas-user] declaring user-defined datatype arrays as PUBLIC

Bodard Fabien gambasfr at ...11...
Fri Mar 4 19:32:34 CET 2005


Le vendredi 4 Mars 2005 14:54, Horst Geisler a écrit :
> Bodard Fabien schrieb:
> >Le jeudi 3 Mars 2005 22:06, Horst Geisler a écrit :
> >>Hey there
> >>I have Problems with declaring user-defined datatype arrays as _PUBLIC_
> >>in Gambas:
> >>
> >>'#I have this user-defined datatyp
> >>clBelegung.class:
> >>
> >>Public  Name As String
> >>Public  Zustand As boolean
> >>---------------------------------------------------
> >>'# and I declare in another global class File
> >>_clGlobal.class:_
> >>STATIC PUBLIC  Eingang AS NEW clBelegung[]
> >>---------------------------------------------------
> >>'#I want use it and its values in different modules like this:
> >>_module1.module:_
> >>DIM i as INTEGER
> >>For i=1 to 7
> >>   clGlobal.Eingang[i].Name ="&23" & i
> >>   clGlobal.Eingang[i].Zustand = True
> >>Next
> >>---------------------------------------------------
> >>_module2.module:_
> >>DIM i as INTEGER
> >>For i=1 to 7
> >>   Print clGlobal.Eingang[i].Name  & ":" & clGlobal.Eingang[i].Zustand
> >>Next
> >>---------------------------------------------------
> >>
> >>If I 'run' this Gambas Project  I get the error messages like
> >>
> >>'Arrays are forbidden here'  (STATIC PUBLIC  Eingang[] AS NEW clBelegung)
> >>or
> >>'Syntax error at line ...'  (STATIC PUBLIC  Eingang AS NEW clBelegung[])
> >
> >In fact you have 2 way :
> >first:
> >define the array size as static array like
> >STATIC PUBLIC  Eingang[6] AS NEW clBelegung
> >
> >else
> >define a dynamic object array and then set each entry with a new class
> >
> >STATIC PUBLIC  Eingang AS NEW Object[]
> >
> >in Public Sub _New()
> >
> >dim i as integer
> >For i = 0 to 6
> >	Eingang[i] = NEW clBelegung
> >next
> >
> >Fabien Bodard
>
> Hey Fabien,
> thanks for your quick help, :-)
> it's a bit tricky for me. I tried to do this, but i'm not very succesfully.
>
> Perhaps i show you my complete code and you can change it directly :-[
>
> *i create following project like i understand your first way you told me*
> -------------------------------------------
> clBelegung.class
> -------------------------------------------
> ' Gambas class file
> PUBLIC Typ AS String
> PUBLIC Adresse AS String
> PUBLIC Pin AS String
> PUBLIC Zustand AS Boolean
>
> -------------------------------------------
> clGlobal.class
> -------------------------------------------
> ' Gambas class file
> 'STATIC PUBLIC Eingang AS NEW clBelegung 'works, as no  array!!
>
> 'STATIC PUBLIC Eingang AS NEW clBelegung[8] 'Syntax error
>
> STATIC PUBLIC Eingang[8] AS NEW clBelegung  'Array are forbidden here
>
> -------------------------------------------
> module1.module *(startup class)*
> -------------------------------------------
> ' Gambas module file
>
> SUB Main()
> DIM i AS Integer
> FOR i = 0 TO 4
>           'works, as no  array!!
> '           clGlobal.Eingang.Typ = "EIN"
> '           clGlobal.Eingang.Adresse = "&232"
> '           clGlobal.Eingang.Pin = i
> '           clGlobal.Eingang.Zustand = 0
>
>           clGlobal.Eingang[i].Typ = "EIN"
>           clGlobal.Eingang[i].Adresse = "&232"
>           clGlobal.Eingang[i].Pin = i
>           clGlobal.Eingang[i].Zustand = TRUE
> NEXT
> module2.Ausgabe
> END SUB
>
> -------------------------------------------
> module2.module
> -------------------------------------------
> ' Gambas module file
> SUB Ausgabe()
> DIM i AS Integer
> FOR i = 0 TO 4
>       'works, as no  array!!
> '       PRINT clGlobal.Eingang.Typ
> '       PRINT clGlobal.Eingang.Adresse
> '       PRINT clGlobal.Eingang.Pin
> '       PRINT clGlobal.Eingang.Zustand
>
>       PRINT clGlobal.Eingang[i].Typ
>       PRINT clGlobal.Eingang[i].Adresse
>       PRINT clGlobal.Eingang[i].Pin
>       PRINT clGlobal.Eingang[i].Zustand
> NEXT
> END
> *
> By the second way you recommended, i insert your code like*
> -------------------------------------------
> clBelegung.class
> -------------------------------------------
> ' Gambas class file
> PUBLIC Typ AS String
> PUBLIC Adresse AS String
> PUBLIC Pin AS String
> PUBLIC Zustand AS Boolean
>
> STATIC PUBLIC  Eingang AS NEW Object[]
>
> Public Sub _New()
>
> dim i as integer
> For i = 0 to 6
> 	Eingang[i] = NEW clBelegung
> next
> end
> -------------------------------------------
>
> i tried different ways, but i find no way to use the variable 'Eingang'
> from both modules!
>
> Thanks a lot for helping,
> Horst

REmove all your STATIC keywords !

Fabien





More information about the User mailing list