Forum > General

Fsearch,if Else problems

(1/4) > >>

captian jaster:

--- Code: --- BEGIN
     ClrScr;
     writeln('Hydraks Console is not installed');
     writeln('In order to use Hydraks Console, some files must be written to your hard drive');
     writeln('Input "Install" on your keyboard and press Enter to install');
     writeln('Input "Close" then press Enter to stop the program and not install');
     Readln(command);
     if command = 'Close' then Halt;
     if command = 'Install' then
      BEGIN
        writeln('Now installing, Please wait....');
        Delay(1000);
        writeln('Creating directorys');
        CreateDir('C:\Hydraks');
        CreateDir('C:\Hydraks\Console');
        CreateDir('C:\Hydraks\Docs');
        writeln('Writing Files');
        assign(file1, 'C:\Hydraks\Console\records.dat');
        rewrite(file1);
        writeln(file1, 'User input records:');
        close(file1);
        Delay(3000);
        assign(file2, 'C:\Hydraks\Docs\About.txt');
        rewrite(file2);
        writeln(file2,'Hydraks is a series of mini programs created by Adam N.Andujar');
        writeln(file2,'Current programs include;');
        writeln(file2,'Hydraks Console');
        close(file2);
        delay(2000);
        ClrScr;
        writeln('Installation complete');
        writeln('Press enter to continue');
        readln;
        Goto 1;
        END
     Else
     BEGIN
       writeln('ERROR! unknown command!');
       writeln('Press enter to close the program.');
       readln;
       Halt;
     END;
--- End code ---

The program should take teh user to the main menu if the folder exists, but it doesnt even thought the folder is there

DirkS:

--- Quote ---The program should take teh user to the main menu if the folder exists, but it doesnt even thought the folder is there
--- End quote ---
I cannot see the relation between this problem and your code... No search or check for directories anywhere in the code as far as I can see.

(and it's been mentioned before: please don't use goto's).

davesimplewear:
if you are relying on goto1 to take you back to your menu then that is where your problem is.

--- Quote ---if fileexists('c:\Hydracks\blah');
then
action you want to happen
--- End quote ---

captian jaster:
if file exist works for folders?

captian jaster:
Grr, still not working!
Heres the whole code. Suggestions welcomed.(i know im using Goto still but it hasnt failed me yet! ill find an alternative when i get better at pascal.)

--- Code: --- program console;

uses classes,crt,dos,windows,SysUtils;

var
 RootDir : Pathstr;
 userfile,file1,file2 : Text;
 records,command,usertext : String;

Label
1,CR;


BEGIN
   ClrScr;
   writeln('Please wait...');
   writeln('Now Loading');
   Delay(1000);
   RootDir := Fsearch('C:\Hydraks\Console', GetEnv(''));
   if RootDir = '' then
   BEGIN
     ClrScr;
     writeln('Hydraks Console is not installed');
     writeln('In order to use Hydraks Console, some files must be written to your hard drive');
     writeln('Type "Install" on your keyboard and press Enter to install');
     writeln('Type "Close" then press Enter to stop the program and not install');
     Readln(command);
     if command = 'Close' then Halt;
     if command = 'Install' then
      BEGIN
        writeln('Now installing, Please wait....');
        Delay(1000);
        writeln('Creating directorys');
        Delay(1000);
        CreateDir('C:\Hydraks');
        Delay(1000);
        CreateDir('C:\Hydraks\Console');
        Delay(1000);
        CreateDir('C:\Hydraks\Docs');
        Delay(1000);
        writeln('Writing Files');
        assign(file1, 'C:\Hydraks\Console\records.dat');
        rewrite(file1);
        writeln(file1, 'User input records:');
        close(file1);
        Delay(2000);
        assign(file2, 'C:\Hydraks\Docs\About.txt');
        rewrite(file2);
        writeln(file2,'Hydraks is a series of mini programs created by Adam N.Andujar');
        writeln(file2,'Current programs include;');
        writeln(file2,'Hydraks Console');
        close(file2);
        delay(2000);
        ClrScr;
        writeln('Installation complete');
        writeln('Press enter to continue');
        readln;
        Goto 1;
        END
     Else
     BEGIN
       writeln('ERROR! unknown command!');
       writeln('Press enter to close the program.');
       readln;
       Halt;
     END;
   END;
 if fileexists('C:\Hydraks\Console') then
  BEGIN
1:ClrScr;
  assignfile(file1, 'C:\Hydraks\console\records.dat');
  writeln('Welcome to the Hydraks console');
  writeln('Here you will be able to input a series of commands to get a series of options');
  writeln('Input Help and Press enter to get a list of some commands');
  readln(command);
  append(file1);
  writeln(file1,command);
  closefile(file1);
  if command = 'Help' then
   BEGIN
     writeln('The console works simply like this,');
     writeln('in between "[]" is were your command goes');
     writeln('What your commanding follows after');
     writeln('eg [read]Records');
     writeln('Whats in between the "[]" stays in lower caps');
     writeln('What follows after starts with a capital letter');
     writeln('Here is a list of some commands:');
     writeln('[open]Records(Read things you have entered into the console)');
     writeln('If the console tells you to put in a certain command in a certain way');
     writeln('You have to enter it in that exact way then press enter');
     writeln('Though you do not have to enter "" if it is in the command');
     writeln('Input "Close" to close the program');
     writeln('Input "Return" to go back');
     readln(command);
     if command = 'Return' then Goto 1;
     if command = 'Close' then Halt;
   END;

  if command = '[Open]Records' then
   BEGIN
     ClrScr;
     assignfile(file1, 'C:\Hydraks\console\records.dat');
     reset(file1);
     while not eof(file1) do
     BEGIN
     readln(file1,records);
     writeln(records);
     END;
     closefile(file1);
     writeln;
     writeln('Input "Return" to go back');
     writeln('Input "Clear" to clear your records');
     readln(command);
     if command = 'Return' then Goto 1;
     if command = 'Clear' then
      BEGIN
        ClrScr;
        assignfile(file1, 'C:\Hydraks\console\records.dat');
        Erase(file1);
        rewrite(file1);
        writeln(file1,'User input records:');
        closefile(file1);
        writeln('Erased records, Press Enter to return');
        readln;
        Goto 1;
      END;
   END
  Else
  BEGIN
    writeln('ERROR! Unknown command!');
    writeln('Press enter to go back');
    readln;
    Goto 1;
  END;
  END;
END.
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version