For TheCounter = 0 To 100 TheArray[TheCounter] = New Class1 <--- you need to create a new object at each element TheArray[TheCounter].I = TheCounter <---- Your error because no object at the element exists. You only created the array.
-- Open WebMail Project (http://openwebmail.org) ---------- Original Message ----------- From: Phan Damily via Gambas-user <gambas-user@lists.sourceforge.net> To: "gambas-user@lists.sourceforge.net" <gambas-user@lists.sourceforge.net> Cc: Phan Damily <phandam...@yahoo.com> Sent: Mon, 29 Jan 2018 04:53:41 +0000 (UTC) Subject: [Gambas-user] Class array - Null Object > Hello everyone. I'm new to Gambas and new to the mailing list. I'm using > v3.10.0 > on Linux.I programmed extensively with VB6 back in the day. So Gambas is > pretty > straight-forward and I'm excited about switching over from Xamarin's C#. > > But I've ran into a situation with Gambas I can't resolve. I've been testing > code ideas, trying to create a working one-dimensional class array. But keep > getting "Null object" errors when trying to assign values to fields. ' > Class1.class > Public I As Integer > Public S As String > ' FMain.class Public TheArray As New Class1[] > > Public Sub cmdTest_Click() > Dim TheCounter As Integer > TheArray = New Class1[] > TheArray.Resize(100) For TheCounter = 0 To 100 > TheArray[TheCounter].I = TheCounter <---- > Null object in FMain TheArray[TheCounter].S = CStr(TheCounter) > Next For TheCounter = 0 To 100 Print > TheArray[TheCounter].I, TheArray[TheCounter].S NextEnd > > I'm sure the solution is pretty simple. But I haven't been able to find an > answer or a working code example for this particular situation. Thanks for > reading. > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Gambas-user mailing list > Gambas-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gambas-user ------- End of Original Message ------- ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user