Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

Posted on 1998-06-20
Medium Priority
264 Views
Okay, i'll make this as organized as I can, since it's really hard to explain!

The Problem:

Maybe it's two problems.  Here goes.  First, I need a way to store the coordinates of a specific character.  Do I do this with a variable?  Here's the tricky part of it.  The variable name has to be 'variable' + number.  The number being if it's the first one plotted, second character plotted or third...etc...  So if i plotted a character and it was the fifth one, it's coordinates would be stored in 'variable5'

Why:

I need it so that i can make a 'path' between randomly placed text characters, and to do that i need to be able to store their coordinates.

Array:

Possibly an array?  If that's what i use, please be EXTREMELY simple when you try to explain how to do it, I get scared enough when I hear the word array...

Conclusion:

So, I geuss I need a way to create a variable midstream, that has the standard name 'variable' plus a number appended onto it.

PS:

I'm afraid an array is what I need, and in that case, please be as simple as you can, I understand NOTHING about arrays. As always, source code is always nice  (:

PPS:  If 100 pts. isn't enough, sorry, it's all i got  (actually 105, geuss i'm lying)   (:
0
Question by:hansell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 2

Accepted Solution

omsec earned 400 total points
ID: 1217111
Hi there !

"First, I need a way to store the coordinates of a specific character.  Do I do this with a variable?"

Yes. I would use a RECORD-Type Variable here.

TYPE
TheCoords = RECORD
X : Integer;
Y : Integer;
Z : Integer; {Z if you need 3D-Coordinates}
END;

Var
Coords : TheCords;

ACCESS
""""""
Coords.X := 5;
Coords.Y := 6;
Coords.Z := 10;

"The variable name has to be 'variable' + number.  The number being if it's the first one plotted, second character plotted or third...etc...  So if i plotted a character and it was the fifth one, it's coordinates would be stored in 'variable5'"

This will NOT work !

You can't assign a number to a variable this way. What you did, would be a String-Operation and this is something completly different. I think the only one way is to use an ARRAY here.
(not only one but best)

First, let me tell you some words about the ARRAY :)

If you understand what an Array is, you will see it is powerfull, usefull and not that hard to get it :)

An Array is a Variable that may store more than one Value of ANY
type. (I won't go into details now). This way... your Idea was not bad with Variable + Number, you just have to write the Index-Number in [ ].

Now, let's write 5 different Numbers to an Array of Byte for example :

VAR
TheArray : Array [1..5] of Byte;
.                .         .
.                .         .
.This is the main Variable Name
.         .
.This shows how many Value in the Array are
.
.This is the DataType, that the Array shall use. You may use ANY ordinal, string or own defined
types here.

OK, now the whole thing with the numbers:

VAR
TheArray : Array [1..5] of Byte;

Begin
TheArray[1] := 25;
TheArray[2] := 50;
TheArray[3] := 90;
TheArray[4] := 30;
TheArray[5] := 18;
End;

This would write the numbers 25,50,90,30 and 18 to "TheArray"

Now you see, reading/writing data to/from an array is more or less same than a "normal" variable. Just add the [x] Where X must always be the Index-Indicator. (The number of variable in the array)

To finish that..here a lil Demo-Program :

Program Example;

Uses
Crt;

Type
Coords = Record
X,
Y,
Z : Integer;
End;

Var
CordsVar : Coords; {only used if you want to access the record
directly. In this Example, we will use
the Array to access it}

AllCords : Array [1..5] of Coords;
OtherData: Array [1..5] of Integer;

HelpVar : Byte; {just to make my life easier, less typing :)}

{note that an Array cannot store values of different types}

Begin
For HelpVar := 1 to 5 do
Begin
ClrScr;
WriteLn;
WriteLn;
WriteLn('Enter X/Y/Z-Cords of point #',HelpVar,' : ');
WriteLn('X:');
WriteLn('Y:');
WriteLn('Z:');
WriteLn;
End;

For HelpVar := 1 to 5 do
Begin
ClrScr;
WriteLn;
WriteLn('Enter some Number to Point #',HelpVar);
WriteLn;
WriteLn('',HelpVar,':.');
WriteLn;
End;

ClrScr;
WriteLn;
WriteLn('Now listing all Data...');
WriteLn;
For HelpVar := 1 to 5 do
Begin
WriteLn('Point ',HelpVar,' : X = ',AllCords[HelpVar].X,' Y = ',AllCords[HelpVar].Y,' Z = ',AllCords[HelpVar].Z);
WriteLn;
WriteLn;
End;
End.

Hoping, this helps, greets, Roger ;)
0

Author Comment

ID: 1217112
Thanks for your help.  I think i can say i have enough understanding of an array to do what I want.

******T H A N K S******
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll