-
I have a two-dimensional array of around 300 records, each with 24 fields, which I am sorting. Can anyone tell me if it's possible to move an entire record (ie, all 24 fields) to another array (this time a one dimensional) in one line, without using pigging loops all the time? The sort function is taking several seconds to do, and I'm sure it's just because of the way I'm swapping records around...
-
Hi,
Why bother physically sorting the list ? Create a linked list. Have a field / column which is a pointer to the next record. Then you only need change this to point to the next record, rather than trying to actually swap the records themseleves.
cheers
Andy
-
Yeah, but a slight problem... no pointers in VB...
-
No pointers in VB????? Well not in a literal defining sense but what do you thing Pass-by-refernce means?.
you can use the MemCopy(could have the name wrong) API to dump the array somewhere or make the array dynamic an just assign it but to be honest I think you shouldn't be using a 2D array rather a UDT.
They are much more flexible and allow you to access their parts for better use of the API copy and array assignments. There are very few situations that I've found multi-dimensional array superior the User-Defined-Types with arrays in them and of them. Even in 3D and 2D graphics programming.
Oh, and I think what andymac meant was linked list pointer not mem-alloc C pointer. A linked list (also created with a struct/class or UDT) holds a reverence to the next or previous (or both) record of the list -in the list itself.
Have a good one
[This message has been edited by Paul282 (edited 02-04-2000).]
-
You could have a second array (1 dimensional)that acts like an index for the data array. That way when you swap two values all you have to do is swap their index values in the smaller index array. When you whish to loop through the array in sorted order just follow the values in the index array.
-
Being an old COBOL programmer, this inability was something I had to get around. It wasn't too hard when I learned about the 'Type' statement. You can define a group of fields within the type and treat them as a single object. Look at Type Statement in you online help.