ONLINE HELP WINDEV, WEBDEV AND WINDEV MOBILEVersion: 151617181920212223242526
 Home | Sign in | English
 OverviewMultiple assignments of arraysSyntaxArray of valuesExamplesMultiple assignments of associative arraysSyntaxExampleMultiple assignments of structures and classesSyntaxRemarksExampleNestingHyphenation WINDEV WEBDEV WINDEV Mobile Others Multiple assignments of arrays, structures and classes Overview The multiple assignment of arrays consists in assigning a set of simple values (boolean, integer, string, real, numeric or currency) to the cells of an array.This multiple assignment is also available for the structures and the classes.Multiple assignments of arrays Syntax1-dimensional array: <1-dimensional array> = [ , , ...] 2-dimensional array: <2-dimensional array> = [ [ , , ...], [ , , ...], ...] 3-dimensional array: <3-dimensional array> = [ [ [ , , ...], [ , , ...], ... ],[ [ , ;, ...], [ , , ...], ... ],...] Array of valuesEach set of values represents a dimension of the array of values. The sets of values can be nested to create an array of values with several dimensions.The numbers of dimensions in the array of values must be consistent: each dimension must have the same number of sub-dimensions. However, a different number of elements can be found for each dimension.Examples: // Array of values not allowed: // The first value of the set has a sub-dimension// The second value of the set has no sub-dimension[[ , ], ] // Array of values allowed: // All the values of the set have a sub-dimension// Each sub-dimension has a different number of elements[[ , [ , , ], [, ]] The dimensions of the array of values must correspond to the dimensions of the array to assign.If the dimensions of the array to assign are not sufficient to store the elements found in the array of values, the array to assign is automatically resized.For a fixed array, if the dimensions of the array to assign are not sufficient to store the elements found in the array of values, the array of values is truncated.If the dimensions of the array to assign are greater than the dimensions of the array of values, the non-assigned elements keep their previous values.Examples // Array of powers of 2Power2 is array of 0 intPower2 = [1, 2, 4, 8, 16, 32, 64, 128, 256] // Array of numbers of days per month // Line 1: non-leap year// Line 2: leap yearNumberDays is array of 2 by 12 intNumberDays = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]] Multiple assignments of associative arrays Syntax = [ [ , ], [ , ],...] The array of values must only contain 2 couples (Key, Value).Each couple is assigned to the associative array by using the equivalence of the syntax: AssociativeArray[Key] = Value.For an associative array without duplicates:If the key does not exist yet, the value is added.If the key already exists, the value is modified.For an associative array with duplicates, all the values are added.Example // Associative array of acronyms of countriesCountry is associative array of stringsCountry = [["FR", "France"], ["US", "United States"], ["DE", "Germany"]] Multiple assignments of structures and classes SyntaxStructure: = [ , , ...] Class: = [ , , ...] RemarksThe members are assigned in the order of declaration.For the classes, the inheritances are ignored: the members of the class are directly assigned.Limitation: this syntax does not operate on the dynamic structures and classes.Example State is Structure Name is string Number is int Prefecture is stringEND Allier is State = ["Allier", 3, "Moulins"] Nesting The syntaxes for multiple assignments can be used on arrays of structures, instances of structures containing arrays, ... State is Structure Name is string Number is int Prefecture is stringEND ArrState is array of 0 StateArrState = [["Ain", 1, "Bourg-en-Bresse"], ["Aisne", 2, "Laon"], ["Allier", 3, "Moulins"]]ArrStateName is associative array of StateArrStateName = [["Ain", ["Ain", 1, "Bourg-en-Bresse"]], ["Aisne", ["Aisne", 2, "Laon"]], ["Allier", ["Allier", 3, "Moulins"]]] Hyphenation You have the ability to describe the arrays of values with line breaks without using the hyphenation syntax (... triple dot).However, the hyphenation syntax must be used to go the next line after the first opening square bracket. For example: State is Structure Name is string Number is int Prefecture is stringEND Allier is State = [... "Allier", 3, "Moulins"] A comma can also be found in front of a closing square bracket: NumberDays = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], ] Minimum version required Version 11 This page is also available for…
 Comments
 Example Array [N,X]
 //Example Array [N,X]arrMensajes is array of 1 by 3 stringsi is int = 1SQLExec(sQuery,ds)WHILE SQLFetch(ds) = 0arrMensajes[i,1] = SQLGetCol(ds, 1) //idarrMensajes[i,2] = SQLGetCol(ds, 2) //numeroarrMensajes[i,3] = SQLGetCol(ds, 3) //mensajei++Dimension(arrMensajes, i, 3)END
 BOLLER
 17 Jul. 2019
 Last update: 11/02/2020Send a report | Local help
 Registered trademarks. Copyright ©2009-2021 PC SOFT. All rights reservedThis website has been developed with WEBDEV and HFSQLWEBDEV, WINDEV Mobile and WINDEV programming