The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
Pascal validation problem
Discuss Pascal validation problem in the Delphi Programming forum on Dev Shed. Pascal validation problem Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 28th, 2004, 12:55 PM
|
 |
Contributing User
|
|
|
|
|
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.
|

January 28th, 2004, 04:44 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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
|

January 28th, 2004, 06:01 PM
|
 |
Contributing User
|
|
|
|
|
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.
|

January 29th, 2004, 12:38 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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:
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|