?
Solved

Complicated...maybe arrays...read...

Posted on 1998-06-20
2
Medium Priority
?
261 Views
Last Modified: 2010-04-16
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
Comment
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
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
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:');
      ReadLn(AllCords[HelpVar].X);
      WriteLn('Y:');
      ReadLn(AllCords[HelpVar].Y);
      WriteLn('Z:');
      ReadLn(AllCords[HelpVar].Z);
      WriteLn;
    End;
 
  For HelpVar := 1 to 5 do
    Begin
      ClrScr;
      WriteLn;
      WriteLn('Enter some Number to Point #',HelpVar);
      WriteLn;
      WriteLn('',HelpVar,':.');
      ReadLn(OtherData[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);
       Write('Additional Number : ',OtherData[HelpVar]);
       WriteLn;
       WriteLn;
     End;
   REadLn;
End.


Hoping, this helps, greets, Roger ;)
0
 

Author Comment

by:hansell
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question