Am 16.07.2015 16:05, schrieb Tobias Boege:
> On Thu, 16 Jul 2015, Rolf-Werner Eilert wrote:
>> Never used a Struct, and now playing around with it I find the help
>> texts cannot help me. This is what I tried:
>>
>> Public Struct Hund
>>     Wau As String
>> End Struct
>>
>> Public Sub Button3_Click()
>> Dim Wauwau As New Hund
>>
>>       Wauwau.Wau = "Bone"
>>
>> Everything ok, but it's ONE Wauwau only. From the description, I would
>> expect an array.
>>
> Why would you expect an array? And of what: an array of Struct Hund or an
> array of Strings inside your one Hund instance? Arrays are only to be
> expected where the "[]" occur.
>
>> So I tried
>>
>> Public Struct Hund
>>     Wau As String[]
>> End Struct
>>
>> Public Sub Button3_Click()
>> Dim Wauwau As New Hund
>>
>>       Wauwau.Wau.Add("Bone")
>>
>> and I get a "Null object" for the Add function.
>>
>> What's going wrong here?
>>
> What you did, in non-Struct terms, is basically this:
>
>    Dim myArray As String[]
>
>    myArray.Add("Bone")
>
> You declared a variable which can hold an array of strings, did NOT create
> the array and tried to add something to it. You should have done
>
>    Dim myArray As New String[]
>
>    myArray.Add("Bone")
>
> or
>
>    Dim myArray As String[]
>
>    myArray = New String[]
>    myArray.Add("Bone")
>
> and similarly
>
>    Dim Wauwau As New Hund
>
>    Wauwau.Wau = New String[]
>    Wauwau.Wau.Add("Bone")
>
> A Struct is just a class without properties, methods and events. It has only
> public variables.
>
> Regards,
> Tobi
>

Ok... so I have to initiate the arrays separately...

Alright, now it's running fine!

What I meant above with the arrays is this declaration:


PUBLIC STRUCT Identifier

   Field 1 [ Embedded array declaration ] AS [ Datatype ]
   Field 2 [ Embedded array declaration ] AS [ Datatype ]
     .
     .
     .
   Field n [ Embedded array declaration ] AS [ Datatype ]

END STRUCT

When you never have worked with it it's confusing because it lets you 
think "a struct is a number of arrays". Then there's no example how to 
actually use it. Maybe the help text could be somewhat more concise here...

Regards
Rolf


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to