Welcome! Log In Create A New Profile

Advanced

Array usage

Posted by Andres Sanchez 
Andres Sanchez
Array usage
December 23, 2008 01:43AM
Hi:

We are using arrays and are having some trouble, (for ex-Clarion we are using them instead of queues).

using arrays of 2 dimensions, for example:
garrEmployees is array of 0 by 5 strings

those 5 columns have Employee No, Name, Start Date, Hourly rate, etc

But in the programm you have to use a number instead of an ID of the field name, this gets real difficult to read the code.

What is the best way to approach this, please take in account that we need to use sort and seek.

We are ruling out TABLES because sometimes you cannot use the TABLE control.



We tried to use array of structures, but we dont know how to do a seek or a sort on this solution, and in the help i didnt find info about this.

TIA

Andres Sanchez

KenKnight
Re: Array usage
December 23, 2008 02:43AM
Hi Andres,

See if using an Associative Array of a dynamic structure or class will work for you. Be sure and read up on the "dynamic" part for speed.

Cheers!
Ken
Al
Re: Array usage
December 23, 2008 06:31AM
Hello Andres

We sometime use views for small arrays, by creating a data source in the project code so it is available globally and we can reference the view in code. A view is dynamic in structure, it can be sorted and operated on just like a file.
You would need to construct a HReadFirst/HReadNext loop for a search but this is very quick on small data sets, because it is all in memory.

You can also use memory tables as global arrays by making them invisible and placing them on the main menu window.


Regards
Al
Paulo Oliveira
Re: Array usage
December 23, 2008 10:37AM
array of structures sample:
wind is int
wname is string="Myself"
wdate is date="20080101"

wstr is structure
Employee_No is int
Name is string
start_date is date
END
arr_str is dynamic array of 0 wstr

wind =ArrayAdd(arr_str)
arr_str[wind]:Employee_No ="1"
arr_str[wind]:Name="Myself"
arr_str[wind]:start_date ="20080101"

wind=ArraySeek(arr_str,asLinear,"Name;start_date",wname,wdate)

ArraySort(arr_str,asMember,"Name;-start_date")

Stefan Bentvelsen
Re: Array usage
December 23, 2008 11:14AM
Hi Andres,

We use also two-dimensional arrays in our software and we defined constants for the items. I.e.:

Constant
csEmpno=1
csName=2
csStartdate=3
csHourlyRate=4
END

In your code you can refer to an item as garrEmployees[x,csEmpno] or garrEmployees[y,csName], etc. Maybe it is a solution for you too ?
Fabrice Harari.pcs.crosspost
Re: Array usage
December 23, 2008 01:04PM
Hi Andres...

If I understand correctly, your only problem is the access Key in your
array. If that is correct, then the answer is clearly ASSOCIATIVE array,
where YOU will define the key type and value

best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

More information on [www.fabriceharari.com]


Andres Sanchez wrote:
> Hi:
> We are using arrays and are having some trouble, (for ex-Clarion we are using them instead of queues).
> using arrays of 2 dimensions, for example:
> garrEmployees is array of 0 by 5 strings
> those 5 columns have Employee No, Name, Start Date, Hourly rate, etc
> But in the programm you have to use a number instead of an ID of the field name, this gets real difficult to read the code.
> What is the best way to approach this, please take in account that we need to use sort and seek.
> We are ruling out TABLES because sometimes you cannot use the TABLE control.
>
> We tried to use array of structures, but we dont know how to do a seek or a sort on this solution, and in the help i didnt find info about this.
> TIA
> Andres Sanchez
>
>
Message forwarded from pcsoft.us.windev
Andres Sanchez
Re: Array usage
December 23, 2008 06:31PM

All of them are great solutions,

I will try everyone to see what's is the best for us.


Thanks to All
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: