TIP: Click on subject to list as thread! ANSI
echo: z3_pascal
to: Keith Bolland
from: Peter Lavender
date: 1996-04-26 17:04:34
subject: Functional problem

Hi Keith,

And thus Keith let it be known to All:

  KB> I'm sure for all you experienced programmers this is going to look
  KB> ridiculous.

I'm not.. I only just started with pascal myself, but I'll take a crack at it.

  KB> All the same.

  KB> Can anyone point out any flaws in this code, and how should I call it
  KB> from the main program block?

You have written a function, genereally a function will take in values and
return one value. So..

  KB> function key(validkeys, grebblevar : string) : char;

The function is called 'key' which is declared as a char, you send it two
value parameters, validkeys and grebblevar of type string.

To call it from where ever, it _could_ look like:

WhatKey:=Key(ValKey,GrebVariable);


Also, just to be picky, formatting your code makes things alot easier to
read. It takes a bit more effort, but it's worth it in the end..

Here is how it looks formatted for easier debugging:


*-=-=-=-=[ Begin: prog.pas ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function key(validkeys, grebblevar : string) : char;

var
   happychar   : char;
   q      : integer;
   finito,invalid,valid : boolean;

begin
  repeat
    happychar := upcase(grebblevar[1]);
      for q := 1 to length(validkeys) do
        begin
          repeat
            if upcase(validkeys[q]) = happychar then
              begin
                key := happychar;
                finito := true;
              end
            else
              begin
                if (q > length(validkeys)) then
                  invalid := true;
                if invalid = true then
                  finito := true
                else finito := false;
              end;
          until finito = true;
        end;
      if invalid = true then
        valid := false
      else valid := true;
  until valid;
end;

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ End: prog.pas ]*


I have to go now, so I'll take a look at the code a bit latter.

It would help if you gave some idea was to what this is supposed to do.

Cya,

Pete

... May fortune favor the foolish. - J. Kirk
--- GoldED/386 2.50 UNREG
--- FMail/386 1.02+
* Origin: Reality Sucks Back from Reality. (3:635/309)
SEEN-BY: 633/267 270
@PATH: 635/309 727 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.