x++


How to get the length of an array?


How to get the length of a string array like
str 30 name[];//dynamic array
I used the following for getting the length,but it showing the error as "the variable is not of the type CLASS."
int len=name.get_length();
It sounds like you might be happier using the Array collection class.
http://msdn.microsoft.com/en-us/library/array.aspx
static void TestArray(Args _args)
{
Array strArray = new Array(Types::String);
;
strArray.value(1, 'abc');
strArray.value(2, 'def');
info(strfmt("%1", strArray.lastIndex()));
}
You need the dimOf function. Take a look to the reference:
http://msdn.microsoft.com/en-us/library/aa597117.aspx
Sorry, there is no build-in function to return the string array size. Since you are in full control what you put in the array, there need not be any!
The built-in function dimof returns the allocated size of the array, which is only of practical value for a fixed size array like str 30 name[20], where dimof(name) returns 20.
A clean way to remain in control, is to use a setter function:
static void TestArray(Args _args)
{
str 30 name[];
int n = 0;
int i;
void nameSet(int _i, str 30 _name)
{
n = max(n,_i);
name[_i] = _name;
}
;
nameSet(2,'abc');
nameSet(4,'def');
for (i = 1; i <= n; i++)
info(name[i]);
}
There is no upper bound index limit, so accessing name[7] is perfectly valid and in this case returns a blank value. This may be used to your advantage, if you always use all holes and never stores a blank:
static void TestArray(Args _args)
{
str 30 name[];
int i;
name[1] = 'abc';
name[2] = 'def';
for (i = 1; name[i]; i++)
info(name[i]);
}
Beware that accessing a higher index (in this case higher than 2) may in fact increase the allocated size of the array.

Related Links

How to show selected items of certain table on the different table in Dynamics AX 2012?
AllowEdit doesn't work properly in Dynamics AX
AX 2012 how to set args record datasource in X++
Clients seem to be running old (buggy) code after XPO project import
Number sequence AX 2012
SSRS MS words report with page break
How can you get a detailed error descriptions in Dynamics AX?
How to get the length of an array?
X++ loop through lines in grid control
Concatenating row values in x++
How do you access a macro in the AOT macro node?
How can I set the Backgoundcolor of an AX2012 Action Pane Button
How to Edit address using X++ in AX 2012
Number sequence issue Ax 2012?
Find code that's running in a Batch Job
What is the _isMexican boolean for in the Global::Checkpower method?

Categories

HOME
hyperlink
prism
nvd3.js
apache-jena
datastore
zend-framework
carousel
simulink
gembox-spreadsheet
interpolation
android-json
gluon-mobile
crystal-lang
character
owin
octave
enthought
docx
shortest-path
guzzle
squashfs
imagemap
dpdk
comparator
xunit
amazon-quicksight
spotipy
winexe
constexpr
utorrent
r-grid
gojs
joomla2.5
hunspell
pop3
python-import
indy10
getlasterror
swagger-php
google-earth-engine
gdata
unordered-map
odoo-website
vmware-fusion
attributeerror
android-ibeacon
install.packages
print-css
contract
knime
stylecop
yii2-user
java-6
oracleclient
backbone-collections
gpg-signature
cmp
mathcad
renaming
async.js
iotivity
http-status-code-401
qiime
kango-framework
bizagi
data-protection
cda
upx
decimalformat
themoviedb-api
rpart
sha512
node-serialport
diff3
actionfilterattribute
cosine-similarity
teaspoon
rickshaw
machine-instruction
device-tree
raygun
cuba
codeplex
tinyxml
qscrollarea
conditionaltagsupport
away3d
printdialog
cnf
css-reset
jquery-1.9
traceability
twisted.web
wimax
redis-py
faye
fusefabric
denied
promotion-code
landscape-portrait
winmain
umra
django-paypal
cloudfiles
cfwindow
sifr3
unmanagedresources

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App