Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4098
Number of posts: 14002

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
2Dimensional Array Error Posted by AlexMK92 on 3 Oct 2011 at 6:22 AM
Hi guys; I am new to the programming world, just beginning to study in my A Levels so hopefully this shouldn't be a problem for you guys
For my homework assignment I need to devise a 2Dimensional array to produce my school timetable. I've looked at my script many times and can't clear the error I face on line "5/28 Timetable.pas
Fatal: Syntax error, OF expected but [ found"
I tried to troubleshoot this by making my "of" uppercase but no luck; below I have attached my script:
program Arrays;

var
//Array Variables\\
myArray : Array [0..5][0..4] OF String;
Counter : integer;
//Lessons Variables\\
C : Computing;
I : ICT;
P : Product Design;
B : BTEC Business;
F : Free Period;
R : Registration;

///////////////Main Program\\\\\\\\\\\\\\\
begin
///////////////Mondays Lessons\\\\\\\\\\\\\\\
myArray[0][0]:='R';
myArray[0][1]:='I';
myArray[0][2]:='C';
myArray[0][3]:='F';
myArray[0][4]:='F';
myArray[0][5]:='F';
///////////////Tuesdays Lessons\\\\\\\\\\\\\\\
myArray[1][0]:='R';
myArray[1][1]:='F';
myArray[1][2]:='I';
myArray[1][3]:='F';
myArray[1][4]:='I';
myArray[1][5]:='B';
///////////////Wednesdays Lessons\\\\\\\\\\\\\\\
myArray[2][0]:='R';
myArray[2][1]:='B';
myArray[2][2]:='I';
myArray[2][3]:='C';
myArray[2][4]:='B';
myArray[2][5]:='F';
///////////////Thursdays Lessons\\\\\\\\\\\\\\\
myArray[3][0]:='R';
myArray[3][1]:='B';
myArray[3][2];='P';
myArray[3][3];='F';
myArray[3][4];='I';
myArray[3][5];='C';
///////////////Fridays Lessons\\\\\\\\\\\\\\\
myArray[4][0];='R';
myArray[4][1];='P';
myArray[4][2];='F';
myArray[4][3]:='F';
myArray[4][4]:='C';
myArray[4][5]:='B';
end.
Any response would be much appreciated, hopefully we can get to the bottom of this ...

Thanks in advance

Alex
Report
Re: 2Dimensional Array Error Posted by salletkd on 7 Nov 2011 at 5:24 AM
Im a newbie, so Im not sure but try doing this:
myArray:Array[0..5,0..4]:of string and later on not [0][0] but [0,0].
Report
Re: 2Dimensional Array Error Posted by DWDuck on 15 Oct 2012 at 8:59 AM
: program Arrays;
:
: var
: //Array Variables\\
: myArray : Array [0..5][0..4] OF String;
: Counter : integer;
: //Lessons Variables\\
: C : Computing;
: I : ICT;
: P : Product Design;
: B : BTEC Business;
: F : Free Period;
: R : Registration;
:
: ///////////////Main Program\\\\\\\\\\\\\\\
: begin
: ///////////////Mondays Lessons\\\\\\\\\\\\\\\
: myArray[0][0]:='R';
: myArray[0][1]:='I';
: myArray[0][2]:='C';
: myArray[0][3]:='F';
: myArray[0][4]:='F';
: myArray[0][5]:='F';
: ///////////////Tuesdays Lessons\\\\\\\\\\\\\\\
: myArray[1][0]:='R';
: myArray[1][1]:='F';
: myArray[1][2]:='I';
: myArray[1][3]:='F';
: myArray[1][4]:='I';
: myArray[1][5]:='B';
: ///////////////Wednesdays Lessons\\\\\\\\\\\\\\\
: myArray[2][0]:='R';
: myArray[2][1]:='B';
: myArray[2][2]:='I';
: myArray[2][3]:='C';
: myArray[2][4]:='B';
: myArray[2][5]:='F';
: ///////////////Thursdays Lessons\\\\\\\\\\\\\\\
: myArray[3][0]:='R';
: myArray[3][1]:='B';
: myArray[3][2];='P';
: myArray[3][3];='F';
: myArray[3][4];='I';
: myArray[3][5];='C';
: ///////////////Fridays Lessons\\\\\\\\\\\\\\\
: myArray[4][0];='R';
: myArray[4][1];='P';
: myArray[4][2];='F';
: myArray[4][3]:='F';
: myArray[4][4]:='C';
: myArray[4][5]:='B';
: end.
: Any response would be much appreciated, hopefully we can get to the
: bottom of this ...
:
: Thanks in advance
:
: Alex
:

: Im a newbie, so Im not sure but try doing this:
: myArray:Array[0..5,0..4]:of string and later on not [0][0] but [0,0].
:

Good day

Firstly you not far off :)

Comparing your code to the array declaration I see your order of the arrays are wrong...

Firstly if you only going to assign a character to the array dont use up all that space by defining a array of string how about an array of char much more efficient...

Secondly when ever defining an array of string ALWAYS set the number of expected charters in this case String[1] would have been great.

Your compiler error should have stopped

Personally when I define an Array I do it like

MyArray : Array[0..5,0..4] of String[1];

vs urs

myArray : Array [0..5][0..4] OF String;

Syntax not wrong but mine read easier and types faster ;)

This is your declaration

myArray : Array [0..5][0..4] OF String;
col row

0..5 i assume are the periods and 0..4 are the days... now look at your code 0..5 is the first dimension (col) and 0..4 is the second dimension (row). But in your code you switch them this will ultimately also stop you compiler as the array is going beyond its definition.

When calling a multi array whether its to allocate value or retrieve it its always Array_Name[Col][Row] or Array_Name[Col,Row];

Another mistake you made is assigning constant string value to a variable without telling pascal you working with constants now therefore I would insert "Const" just before "//Lessons variable\\"

Basically array definition are as follows in Pascal

Array_Name : Array[start_value..End_Value] of [variable_type]

After these changes you should be running
Darkwing Duck aka DWduck signing off :)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.