[Gambas-user] Accessing elements of dynamic control arrays. Not possible outside of creating function? Help please ^_^

Fabien Bodard gambas.fr at ...626...
Fri Nov 7 12:02:49 CET 2008


Public MySW as New Object[]


 PUBLIC SUB btnAdd_Click()
   Dim hSock as SWSocket
   hSock = new SWSocket;
   MySW.Add(hSock)
    hSock.DoSomeMethod()

 END

 PUBLIC SUB Timer_Tick() 'or whatever it is, not important
  Dim hSock as SWSocket
    FOR each hSock in MySw
        hSock.SendData
    NEXT
 END


And you can access from the outside too




2008/11/7 Robert Moss <the.at.robert at ...626...>:
> OK,   //CODE EXAMPLE AT END OF MSG
>
> I have a subclass of Socket, Which is a socket, but contains some extra
> data, so that in the event handler, I have more than just the TAG property
> to work with.
>
> It seems that I cannot have a dynamically sized array.
>
> When i try putting:
>
> PUBLIC mySW[] as SWSocket
>
> At  the top of the form class, it says "Arrays are forbidden here"
> And if I declare it like:
> Sub Form_Open ()
>    DIM mySW[] as SWSocket
>
>
> it says syntax error.
>
> It's requiring me to set an array size, which isn't good, and on top of
> that, I cannot access the socket outside of that function (and i believe the
> sockets are destroyed once the open sub ends)
>
> I'd like a button on the form that works like this
>
> PUBLIC SUB btnAdd_Click()
>    mySw[iNextSw] = new SWSocket;
>    mySw[iNextSw].DoSomeMethod()
>    INC iNextSw
>
> END
>
> 'With a timer that does:
>
> PUBLIC SUB Timer_Tick() 'or whatever it is, not important
>    DIM X as Integer
>    FOR X = 0 TO (iNextSw - 1)
>        mySw[X].SendData
>    NEXT
> END
>
> How can I do this?
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>




More information about the User mailing list