Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
More efficient way of checking parameters
I'm very new to Pascal, been learning about it for around 4hrs now. Below is the start of a program that is in the works. It will be a command line application taking three parameters: start ip (sIp) end ip (eIp) and a DNS server address.
sIp, eIp: AnsiString;
begin (* Main *)
for i := 0 to ParamCount do
if ParamStr(i) = '-s' then
sIp := ParamStr(i +1);
if ParamStr(i) = '-e' then
eIp := ParamStr(i +1);
if ParamStr(i) <> '-s' then
if ParamStr(i) <> '-e' then
if ParamStr(i) <> eIp then
if ParamStr(i) <> sIp then
writeln('Invalid parameter or input specified, exiting...');
end. (* Main *)[/code]
I would like the application to check each parameter and either assign a value from the parameter or exit if invalid data is passed to the application. As you can see the nested if statements are not the most efficient way of checking for invalid input. Could someone please demonstrate a more efficient way of performing this task?
I've tried using the case statement to assign the parameters as a variable and or to logically check data passed to the application. Of course neither of these attempts worked because of the data-types used.