#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46

    Pascal validation problem


    I couldnt see a forum for Pascal, so I thought this would be the best place to put it.

    In the script Im using, I have a variable called name, that contains the persons name. Now, I want the script to return an error if any numbers are entered in the variable.

    I was told the only way to do this was to break it down into an array of each letter and then check each one for a number. Now, if anyone could find another way, or write me a few lines that would do the above, Id be most grateful.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    Depends on how strict your pascal compiler (or your professor) is . Standard Pascal as defined by Niklaus Wirth didn't have a string type. Turbo Pascal did add a string type extension to the language. So you might want to tell us how you've defined the variable "name". The following should work somewhat on Turbo Pascal (untested code)
    Code:
    Function IsOk(name : string) : boolean;
    var
       i: integer;
    begin
        IsOk := false;
        for i := 1 to Length(name) do
        begin
            ch := name[i];
            if (ch in ['0'..'9']) then
            begin
                IsOk := true;    
                i := Length(name);
            end;
        end;
    end;
    Note: I didn't use the Break or Result keywords as they're specific to Delphi, not Pascal.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    295
    Rep Power
    46
    Yeah, its slowly working with a little bit of reworking. Thanks for your help.

    One more thing. Can I create a statement that allows me to print the page?

    And yes, Im using Turbo Pascal.
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,640
    Rep Power
    4247
    Been a while since I did any turbo pascal programming for DOS, but IIRC, issuing an INT 5 interrupt intstruction would cause the BIOS to print screen. In Turbo Pascal, you would fire off the interrupt like this:
    Code:
    Intr ($5);
    However, if you want to send all the output to the printer, there are a couple of ways to do it. First you could redirect your program output to the printer like this:
    C:\> program > prn

    Second, if you know how to write to files, you could open a file called "prn" which would access the printer. Then you write to it just like you write to any other file and it will print on the printer. Don't forget to hit form-feed at the end, if you're not using a dot-matrix (now I'm showing my age ), otherwise some printers will not eject the page.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo