Board index » delphi » HELP: Having trouble with basic procedure!!!

HELP: Having trouble with basic procedure!!!

I am currently a new pascal student and would like some quick help with
this problem involving procedures.

In the program there are two procedures:  The first reads in the users
input data and saves it in a variable.  The second procedure must use the
value stored to the variable in the first procedure to perform the given
operation.  What I need to know is how to use the value stored in the
variable in the first procedure in the second procedure.

YOUR HELP IS MUCH APPRETIATED!!

                   -Eric-

 

Re:HELP: Having trouble with basic procedure!!!


On 23 Sep 1996, Eric Mauskopf wrote:

Quote
> In the program there are two procedures:  The first reads in the users
> input data and saves it in a variable.  The second procedure must use the
> value stored to the variable in the first procedure to perform the given
> operation.  What I need to know is how to use the value stored in the
> variable in the first procedure in the second procedure.

To access the variable from the first procedure in the second procedure,
you must NOT declare that variable inside the first procedure because if
you do so,only the first procedure will access it, as it is a local
variable for that procedure only.

Declare the variable in the main program ,like this:

program xxx;
uses <unit names>;
var <variable>:<type>; {this is it}

procedure <name>;
begin
{store data to <variable> }
end;

procedure <name 2>;
begin
{output data from <variable>}
end;

begin
.
.
.
end.

Hope this helped ya...

===============================
D-Fens - gabr...@lbzbph.sfos.ro
===============================

Re:HELP: Having trouble with basic procedure!!!


thanks for the help I appretiate it

----------

Quote
> From: Gabi Oprea <gabr...@lbzbph.sfos.ro>
> To: Eric Mauskopf <Eric.Mausk...@worldnet.att.net>
> Cc: info-pas...@ARL.MIL
> Subject: Re: HELP: Having trouble with basic procedure!!!
> Date: Tuesday, September 24, 1996 6:23 AM

> On 23 Sep 1996, Eric Mauskopf wrote:

> > In the program there are two procedures:  The first reads in the users
> > input data and saves it in a variable.  The second procedure must use
the
> > value stored to the variable in the first procedure to perform the
given
> > operation.  What I need to know is how to use the value stored in the
> > variable in the first procedure in the second procedure.

> To access the variable from the first procedure in the second procedure,
> you must NOT declare that variable inside the first procedure because if
> you do so,only the first procedure will access it, as it is a local
> variable for that procedure only.

> Declare the variable in the main program ,like this:

> program xxx;
> uses <unit names>;
> var <variable>:<type>; {this is it}

> procedure <name>;
> begin
> {store data to <variable> }
> end;

> procedure <name 2>;
> begin
> {output data from <variable>}
> end;

> begin
> .
> .
> .
> end.

> Hope this helped ya...

> ===============================
> D-Fens - gabr...@lbzbph.sfos.ro
> ===============================

Re:HELP: Having trouble with basic procedure!!!


Quote
"Eric Mauskopf" <Eric.Mausk...@worldnet.att.net> wrote:
>I am currently a new pascal student and would like some quick help with
>this problem involving procedures.

>In the program there are two procedures:  The first reads in the users
>input data and saves it in a variable.  The second procedure must use the
>value stored to the variable in the first procedure to perform the given
>operation.  What I need to know is how to use the value stored in the
>variable in the first procedure in the second procedure.

PROCEDURE FirstOne(VAR data: integer);
{ This procedure returns an integer value in the 'data' variable}

PROCEDURE SecondOne(saved_data: integer);
{ This procedure does something with the 'saved_data' integer variable }

VAR int_data: integer;
BEGIN
        Writeln('The initial value of int_data is ', int_data);
        FirstOne(int_data);
        Writeln('After FirstOne(), the value of int_data is ', int_data);
        SecondOne(int_data);
        Writeln('After SecondOne(), the value of int_data is ', int_data)
END.

--
Robert B. Clark <rcl...@iquest.net>
"Anyone who considers protocol unimportant has never dealt with a cat."  --L. Long

Re:HELP: Having trouble with basic procedure!!!


Hi Eric,

Let's walk through your questions:

Quote
> In the program there are two procedures:  
> The first reads in the users input data and saves it in a variable.  

Define a procedure that reads the user input data.
Important is that the variable in the procedure heading is a VAR variable,
in this case the data is not static and passed through by the procedure.

PROCEDURE READ_USER_INPUT(VAR VALUE : DATATYPE {e.g. Byte, Word, etc});
BEGIN
  --> read the user input of type datatype
END;

Quote
> The second procedure must use the value stored to the variable in the first
> procedure to perform the given operation.  

PROCEDURE USED_DATA;

VAR VALUE : DataType;  { This is a local variable, only used in this procedure }

BEGIN
  READ_USER_INPUT(VALUE);
  { Here you call the first procedure and use the variable VALUE }
  ---> do something with the user input data stored in VALUE.
END;

Hope this help.

drs.ing. Dinesh Ramsaransing
The Netherlands

Re:HELP: Having trouble with basic procedure!!!


    ???????

    ARE YOU REALLY *NEW* IN PASCAL PROGRAMMING ????

    There are variables known as Global.

    This is your so simple solution.

    In the future, read manuals before posting.

--

          ___                                              ___
          L_|_                                            _|_J
         ( -O>                                            <O- )
      ___//\J  __________________________________________  L/\\___
     //-,\    |                                          |    /,-\\
    || / \\___L   AVONTURE Christophe (c) AVC Software   J___// \ ||
  _ ''/\/ '---J    Christophe.Avont...@is.belgacom.be    L---' \/\'' _
 / \ //\\.    |__________________________________________|    .//\\ / \
|_/\'/  ||                                                    ||  \'/\_|
     '   ||_         "Make sure that, always!, you            _||   '
         |__)       reply to my private mail adress"         (__|

Delphi Super Page: http://sunsite.icm.edu.pl/archive/delphi/_index.html

 "Postings are personnal, and don't reflect Belgacom's opinion"

Other Threads