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

Dynamics AX 2012 parsing Int32 to table field integer
Cancel Sales order packing slip through x++
Transferring open account records between customers
How to make sure that a form is only opened once?
Extend system menu in Dynamics AX 2012?
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?

Categories

HOME
service-worker
go
porting
gdb
telegram
github-for-windows
object
google-cloud-functions
pyqt4
hpc
mvc5
heap
plist
mod-security
frequency-distribution
cumulocity
gruntfile
azure-powershell
microsoft-dynamics-nav
fileserver
cfml
sencha-touch
rubymotion
inno-download-plugin
interpreter
comparator
google-api-client
game-theory
froala
dapper-extensions
bulletphysics
mat
nstimer
handler
boost-asio
volatile
weather
turfjs
clickjacking
twos-complement
hibernate-search
lubridate
roblox
video-capture
password-protection
ods
css-position
spring-mvc-test
trigonometry
visa
sharp-snmp
subclipse
avcapturedevice
apache-directory
double-click
libgphoto2
openrasta
page-replacement
wpas
opengl-4
jqchart
rackspace-cloud
renaming
cronexpression
pacemaker
uicolor
jquery-jscrollpane
lean
kango-framework
phpwebsocket
ikiwiki
httpruntime.cache
iokit
file-move
vigenere
jdi
poppler
fuelcms
android-launcher
extjs-grid
branch-and-bound
snoop
snackbar
phpldapadmin
openbabel
document-repository
sip-server
big-ip
genymotion-call
named-parameters
build-script
extjs2
synapse
koala
xmltodict
http-patch
breakout
cnf
nebula
onmousemove
window-decoration
gobject-introspection
msr
vs-android
google-wave
wysiwym
sqlobject

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App