Thread overview
arrays
Jan 29, 2008
tytower
Jan 29, 2008
BCS
Jan 29, 2008
torhu
January 29, 2008
[code]
this() {
	char[][] data ;

	char[] dataNumber = "1";
	char[] date = "10/12/08" ;
	char[] m_details = "test";
	char[] m_code = "340" ;

	char[] m_debit = "3480.00";
	char[] m_credit;

	data[0]= dataNumber;
	data[1]= date ;
	data[2]= m_details;
	data[3][ m_code;
	data[4]= m_debit;
	data[5][ m_credit;
[/code]
Compiles OK but gives error
[code]
"tango.core.Exception.ArrayBoundsException@transaction(56): Array index out of bounds"[/code]

January 29, 2008
Reply to tytower,

> [code]
> this() {
> char[][] data ;
> char[] dataNumber = "1";
> char[] date = "10/12/08" ;
> char[] m_details = "test";
> char[] m_code = "340" ;
> char[] m_debit = "3480.00";
> char[] m_credit;

  data.length = 6;

> data[0]= dataNumber;
> data[1]= date ;
> data[2]= m_details;
> data[3][ m_code;
> data[4]= m_debit;
> data[5][ m_credit;
> [/code]
> Compiles OK but gives error
> [code]
> "tango.core.Exception.ArrayBoundsException@transaction(56): Array
> index out of bounds"[/code]

untill you say otherwise a dynamic array has size zero.


January 29, 2008
tytower wrote:
> [code]
> this() {
> 	char[][] data ;
> 
> 	char[] dataNumber = "1";
> 	char[] date = "10/12/08" ;
> 	char[] m_details = "test";
> 	char[] m_code = "340" ;
> 
> 	char[] m_debit = "3480.00"; 	char[] m_credit;
> 
> 	data[0]= dataNumber;
> 	data[1]= date ;
> 	data[2]= m_details;
> 	data[3][ m_code;
> 	data[4]= m_debit;
> 	data[5][ m_credit;
> [/code]
> Compiles OK but gives error [code]
> "tango.core.Exception.ArrayBoundsException@transaction(56): Array index out of bounds"[/code]
> 

'char[][] data;' doesn't allocate anything but an array reference.  So it's just an empty array to begin with.  If you print its length, you'll see that it's '0'.

Use the append operator instead:

data ~= dataNumber;
data ~= data;

etc.