Re: Create Structure



In article
<5dd6376f-fcd5-474e-9f38-4208ab6d0c96@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
shapper <mdmoura@xxxxxxxxx> wrote:

[snip]

Hi,

I haven't use Matlab for 1 year and I am getting back to it.
I have been using a lot of Object Oriented languages such as VB.NET
and C#.
I think the confusion is coming from it ...

For example, in VB.NET I would do something like:

Structure Person
Dim Name As String
Dim Phone As Integer
Dim Country As String
Dim Birthday As String
End Structure

Now I have the structure fields and their types defined.

Then I could create a define any variable of type Person as follows:

Dim Employee_1 As New Person()
Employee_1.Name = "John"
Employee_1.Phone = "0211131"
Employee_1.Country = "US"
Employee_1.Birthday = "10.01.1980"

Dim Employee_2 As New Person()
Employee_2.Name = "Mary"
Employee_2.Phone = "0211231"
Employee_2.Country = "UK"
Employee_2.Birthday = "11.04.1982"

Then I could create a list of Employees
Dim Employees As List Of (Person)

Finally I would add the Employees to my list:
Employees.Add(Employee_1)
Employees.Add(Employee_2)

But as you see first of all I create the structure so I can define its
fields.

But when you write:
Employee_1 = struct('Name',{Bill},'Phone',{234234},'Country',
{France},'Birthday',{21.04.1900});

You create the variable and fill the values all at the same time. And
if by mistake I do something like:
Employee_2 = struct('Name',{Andrew},'Phone',{232343});

Then what happens when I added it to an array?

Sorry, just looking for the best way to do this.
My brain is still working with "well" defined objects.

Thanks,
Miguel

If you have only a few employees to keep track of here is what I would
do:

employees(1).Name = 'John';
employees(1).Phone = '0211131';
employees(1).Country = 'US';
employees(1).Birthday = '10.01.1980';

employees(2).Name = 'Mary';
employees(2).Phone = '0211231';
employees(2).Country = 'UK';
employees(2).Birthday = '11.04.1982';

It's that simple.

If you have many employees to enter then I would allocate the structure
array first. Here is one of many ways to do this:

num_employees = 100;
c = cell(1,num_employees);
employees = struct('Name',c,'Phone',c,'Country',c,'Birthday',c);

and then just fill in the structure array as before.

If you are reading your employee info from a file then I might go about
this in a different way depending on how the info is stored.

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.
.



Relevant Pages

  • Re: Retrieving data from query using If, Then, Else
    ... Private Sub Form_Current ... Dim s As String ... Dim rs As DAO.Recordset ... I am currently using the following code to retrieve each employees ...
    (microsoft.public.access.formscoding)
  • Re: Listbox with selection of start and end date
    ... it shows all employees, so I am missing something somewhere. ... Private Sub CmdPrintEmplData_Click ... Dim varSelected As Variant ... Dim strWhere As String ...
    (microsoft.public.access.formscoding)
  • Re: Sort multi-dimensional array using vb.net
    ... I have one question: how about if I have employees ... the recordset in an array and sort them according to the. ... Dim aEmplSQL: aEmplSQL = getEmplSQL ... Dim aEmplSORT: aEmplSORT = orderNET ...
    (microsoft.public.scripting.vbscript)
  • RE: Beginner VBA help with multiple tables
    ... information about the employees, and one where the new data is going to be ... Dim rs as DAO.Recordset 'This holds the records to loop ... these totals to a different table, ... subtract VacationHrs to get the VacationBalance. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Create Structure
    ... Apparently they do when you build the array the way I wrote it: ... Dim Phone As Integer ... Dim Country As String ... Then I could create a list of Employees ...
    (comp.soft-sys.matlab)

Loading