Solved

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

Posted on 1998-06-20
2
241 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
2 Comments
 
LVL 2

Accepted Solution

by:
omsec earned 100 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now