|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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
|
||||
|
||||
|
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 Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
||||
|
||||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Pascal validation problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|