[Gambas-user] How to make an array

Yahoo olivier.cruilles at yahoo.fr
Tue May 5 18:49:09 CEST 2020


Hello,

I thing the simple way to manage an Array for various kind of fiels could be an Array of Class

Example:

- Create a Class named ‘ClassUserRecord’ containing:

	Public FirstName as String
	Public LastName as String
	Public Address1 as String
	Public Address2 as String
	Public PhoneNumber as String

- In your Form or module, instantiate an Array based in this Class

	Public ArrayOfUser as New ClassUserRecord[]

- To add a new entry in the Array

Public Sub Add_New_User(FirsName as String, LastName as String, Address1 as String, Address2 as String, PhoneNumber as String)

	Dim NewUserRecord as ClassUserRecord

	NewUserRecord = New ClassUserRecord

	NewUserRecord.FirstName = FirsName
	NewUserRecord.LastName = LastName
	NewUserRecord.Address1 = Address1
	NewUserRecord.Address2 = Address2
	NewUserRecord.PhoneNumber = PhoneNumber
		
	ArrayOfUser.Add(NewUserRecord)

End

- To list all User in the Array

Public Sub List_User_Array()

	Dim ItemUser as ClassUserRecord

    if ArrayOfUser <> NULL Then
		print “Sorry, no User in the Array for now”
	End If

	For Each ItemUser In ArrayOfUser
		Print “FirstName: “ & ItemUser.FirstName
		Print “LastName: “ & ItemUser. LastName
		Print “Address1: “ & ItemUser. Address1
		Print “Address2: “ & ItemUser. Address2
		Print “PhoneNumber: “ & ItemUser. PhoneNumber
	Next

	Print “Number of records: “ & ArrayOfUser.Count

End

Etc…...

This is just examples….

— 
Olivier Cruilles


On May 5, 2020 at 10:22:05, T Lee Davidson (t.lee.davidson at gmail.com) wrote:

On 5/5/20 8:39 AM, Dag Jarle Nerland Johansen - Gambas wrote:  
> Hi,  
> I got unsure how to create a dynamic two-dimensional array.  
> I need to read in a CSV for processing addresses.  
> That means a variable length of the array, but the field numbers are always the same.  
> forename, surename, mail ...  
> Can anyone help,  
> thanks,  
> (I know I should know this by now but I only program now and then with long pauses in between)  
> Dag  

Perhaps an array of Collection (Collection[]) would be better suited.  


--  
Lee  

----[ http://gambaswiki.org/wiki/doc/netiquette ]----  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200505/f9f150ff/attachment-0001.html>


More information about the User mailing list