Change array dimensions programatically

Hello my name is Vittorio, I would like to know if it is possible to assign the dimension of an array programatically? I know that is possible to assign the dimension of an array in the properties window of the declared variable, but this is a very statical situation, i need to manage a dinamical situation. Thank you

You could do this using Temporary tables. Just create a new table TempMyTable 1: “i”:integer; 2: “j” integer; 100 :MyDecimal : decimal. Now ust create as many dimensions as you need.

Hi David Thank you for your quick response, Maybe I expressed myself in a wrong manner. I would like to set the length of an array programatically, because in the normal way I would declare a variable in global variables and assign its type then I would have to go on the properties window of the variable and set the dimensions property to, for exampl 10, that means that the variable is one-dimsional array variable with a maximum value of dimensions being 10->I would like to change dynamically this value…HOW?? Thank you very much david

No way to change that. Your only chance is to define the number of dimensions needed big enough and pray that your code does not exceed the maximum number of defined dimensions.

quote:

Your only chance is to define the number of dimensions needed big enough and pray that your code does not exceed the maximum number of defined dimensions.

And to avoid this need for praying, use a temporary table, as David recommended. In this sense, Navision is different to other programming languages (e.g. VB) where you can “re-dimension” arrays during runtime. In Navision you have to define the size of the array, and no way to enlarge it during run-time. Using temporary tables is an elegant solution, and really easy once you put together your first example. Saludos Nils

quote:

You could do this using Temporary tables. Just create a new table TempMyTable 1: “i”:integer; 2: “j” integer; 100 :MyDecimal : decimal. Now ust create as many dimensions as you need.
Originally posted by David Singleton - 2006 Mar 21 : 07:08:29

And if you use a table only as temptable, you don’t even need to put it in the license of the customer.

Hi Vitriod, I am guessing that you are new to Navision. This is the Navsion way. Don’t fight Navision, work with it. Basically your Temporary table will be indexed just like a normla array, i.e. NewVar := MyArray[2,5]; would be if MyTempRec.Get(2,5) then NewVar := MyTempRec.MyValue else NewVar := 0; if the extra code is a problem , you an put it in a function. It is differnt to what ever you are used to, but it is the way to do it. ANd its much more flexible that arrays. I ver very rarely use arrays, since you have so muchmore flexibility with Temp Tables. PS I will move this to the beginer forum.

Thanks to all of you…I adopted a temporary table…but my qiestion is how to clear all of its values…I tried with Record.Deleteall and nothing happens and with clear(record) that seems to clear out the values instead they remain intact…thank yot

Vittorio, use these temporary tables as you would use any normal table - the first, and most important step, create the variable in the Globals, set type to record and subtype to the respective table, then enter the properties and set the property temporary to yes. When calling the object, where you use that temporary record, the record (and temporary table) will be empty, the same happens after the object terminates and the temporary record does not exist anymore. variablename.DELETEALL will in fact delete all the temporary records during runtime, and CLEAR(variablename) will completely clear the current record. Of course you must use INSERT and MODIFY as usual to create and modify new records in that temporary variable. Just feel free to post your code, I am sure there are enough people around willing to help. Saludos Nils

quote:

Vittorio, use these temporary tables as you would use any normal table - … then enter the properties and set the property temporary to yes. … variablename.DELETEALL will in fact delete all the temporary records during runtime, … Saludos Nils
Originally posted by nilsm - 2006 Mar 22 : 16:06:18

Nils, sorry to have to correct you here, but here is the correct procedure… 1/ Create the Variable then set the Porperty Temporary to YES. 2/ CLose Navision, go out side take a walk around the block, come back. 3/ Re-open Navision oen the porperties and check that the porperty Temporary is set to yes. 4/ Find a friend that knows Navision, have him/her check that the Temporary porperty is set to yes. 5/ Create Backup and make certain that you are working on a backup database. 6/ Check once more that the Property Temporary is set to Yes. 7/ Write the code MyTempRecord.DELETEALL; [:D] [:D] [:D] [:D] [:D]

Thanks for the reminder, David. Especially if you are working with tables like G/L Entry, Cust. Ledger Entry, Item Ledger Entry or Value Entry, isn’t it [:D] Anyway, I hope no develper will in fact “test” their developments in a live db… [Oops!] Saludos Nils

… or the other way around… Keep on INSERTing records of a temporary variable, just to figure out later that it hasn’t been temporary at all - at least your sales figures and P&L might look really great [:P] Saludos Nils

Hi,

You can use loop for dinamical array it properly work, try it.

thanks!!!