Closed Thread
Results 1 to 4 of 4

Thread: Win32CRT ClrScrn Function

  1. #1
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Win32CRT ClrScrn Function

    HI all.

    I am doing this hangman type program...so basically I have to hide the word after i type it. So I use this function 'ClrScr' which needs the Util Win32CRT (I call it util, coz its in the util bit ). So everything is fine, until I get to the end of the program. I cant exit. Once I get to the end of the program (running), it says 'Inactive' at the top of the windows, and I press Enter and everything and nothing happens.

    I exit, and then I delete the Win32CRT and the 'ClrScr' and everything runs fine again.

    Any help? If you want I can post the entire code, but its 450 lines long 0_0

    Thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Win32CRT ClrScrn Function

    After doing a little bit of research...

    The code would probably be helpful, since the CRT unit has a lot of different functions/settings that may be involved in your issue. You also didn't mention some important things like:
    1) What compiler are you using?
    2) What version of WinCRT32 are you using?
    3) What platform are you on (Pascal runs on Linux as well)
    4) Have you run your program in a debugger to see what's happening?
    5) Do you get any compiler warnings?
    etc.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Win32CRT ClrScrn Function

    1) I'm using the Pascal part of Borland Delphi
    2) Um...I dont really know. I just took the one my teacher gave me. If it helps, I have got Delphi Second Edition v7.2. So the Win32CRT that works with that one.
    3) Im on Windows Vista.
    4) Is debugger mode where you press F7? And you run through the program step by step? Well, the F7 doesnt really like Win32CRT (as my teacher has told me so), since it displays 'Win32CRT.pas not found'. And then i press Ok, and a box with quite a lot of numbers and letters pops up. So I cant really use Debugger mode, if this is what you are talking about (Sorry, not really good with technical side of Computers).

    5) No warnings. Only a few variables may not have been initialised. Thats all.

    Here's the code. Hope you don't mind reading this long piece of code

    Code:
    Program Hangman;
    
    {$APPTYPE CONSOLE}
    uses
      SysUtils,
      StrUtils,
      Win32CRT;
    
    Type
    TGuessStatusArray = Array[1..20] Of Char;
    TLettersGuessedArray = Array[1..26] Of Char;
    Var
    FileA: textfile;
    NewPhrase, EntirePhrase, Word1 : String;
    PhraseHasBeenSet : Boolean;
    PhraseGuessed : Boolean;
    Ptr3,Ptr4 : Integer;
    GuessStatusArray : TGuessStatusArray;
    LettersGuessedArray : TLettersGuessedArray;
    NextGuessedLetter, Choice : Char;
    Index,index2, Ptr,Ptr2,Count,Count2, CountGos, Count3, numberPhrases: Integer;
    
    Procedure DisplayMenu;
      Begin
        Writeln('__________________________________');
        Writeln;
        Writeln('1. Makes new word/phrase');
        Writeln;
        Writeln('2. Make a Guess');
        Writeln;
        writeln('3. Display History of Letters');
        writeln;
        writeln('4. Guess the Entire Phrase');
        writeln;
        writeln('5. Choose a Random Phrase');
        writeln;
        writeln('6. Enter New Phrase Into Random Phrase');
        writeln;
        Writeln('7. End');
        Writeln;
      End;
    
    Function GetNewPhrase : String;
      Var
        PhraseOK, LettersOk, Phrase, Outnow : Boolean;
        ThisNewPhrase : String;
        Count: Integer;
    
      Begin
        Repeat
          OutNow:=False;
          Write('Key in new phrase ...(letters and any Spaces) ');
          Readln(ThisNewPhrase);
          ThisNewphrase:=UpperCase(Thisnewphrase);
          ThisNewphrase:=Trim(ThisNewphrase);
    
          while (Outnow<>True)
          do
          begin
    
          repeat
          Index2:=0;
          Phrase:=False;
    
          For count := 1 to Length(ThisNewphrase)
          do
          begin
    
          Case ThisNewphrase[Count] of
    
          'A'..'Z',' ':
    
          index2:=index2+1;
    
          else
          Phrase:=True;
    
          end;//case
          end;//count
    
          until (Phrase=True) or (Index2=Length(ThisNewphrase));
    
          if Phrase=True
          then
          begin
          writeln('Only Letters allowed');
          writeln('Please type in a New Phrase');
          readln(Thisnewphrase);
          ThisNewphrase:=UpperCase(ThisNewphrase);
          end
    
          else
          Outnow:=True;
    
          end;
    
          If not (Length(ThisNewPhrase) IN[10..20])
          Then
            Begin
              PhraseOK := False;
              if (Length(ThisNewPhrase) < 10)
               then
    
              Writeln('Not enough letters ... ')
                else
              writeln('Too many letters...');
            End
          Else
            Begin
              PhraseOK := True;
              GetNewPhrase := ThisNewPhrase;
            End;
    
        Until (PhraseOK = True)
    End;
    
    Procedure SetUpGuessStatusArray(NewPhrase : String;
                                    Var GuessStatusArray : TGuessStatusArray);
      Var
        Position : Integer;
      Begin
        For Position := 1 To Length(NewPhrase)
        Do
          Begin
            If NewPhrase[Position] = ' '
              Then GuessStatusArray[Position] := ' '
              Else GuessStatusArray[Position] := '*';
    
          End;
      End;
    
    Procedure DisplayCurrentStatus(PhraseLength : Byte;
                                    GuessStatusArray : TGuessStatusArray);
      Var
        Position : Integer;
      Begin
        For Position := 1 To PhraseLength
          Do Write(GuessStatusArray[Position]);
        Writeln;
      End;
    
    Function GetNextLetterGuess : Char;
      Var
        Position : Integer;
        GuessedLetter : Char;
        LetterOK: Boolean;
    
      Begin
        repeat
        LetterOK:=False;
        Writeln;
        Write('Next guess ? ');
        Readln(GuessedLetter);
        GuessedLetter:=UpCase(GuessedLetter);
    
         If not (GuessedLetter IN['A'..'Z'])
         then
         writeln('Must be an alphabetical letter. Plz Try again')
         else
         LetterOk:=True;
    
        until LetterOk=True;
    
      Result:=GuessedLetter;
    
      End;
    
    Function AllLettersGuessedCorrectly(GuessStatusArray: TGuessStatusArray;
                                        NewPhrase : String) : Boolean;
      Var
        Position : Integer;
        MissingLetter : Boolean;
      Begin
        MissingLetter := False;
        Position := 1;
        Repeat
          If GuessStatusArray[Position] <> NewPhrase[Position]
            Then MissingLetter := True
            Else Position := Position+1;
        Until (MissingLetter = True) or (Position = Length(NewPhrase)+1);
    
        If MissingLetter = False
          Then AllLettersGuessedCorrectly := True
          Else AllLettersGuessedCorrectly := False;
      End;
    
      Function CountNumberphrases:Integer;
    
      var
      FileA: Textfile;
      Count: integer;
    
      begin
      AssignFile(FileA, 'Myphrases.txt');
      Reset(FileA);
      Count:=0;
    
      while not Eof(FileA)
      do
      begin
    
      readln(FileA);
      Count:=Count+1;
      end;
      result:=Count;
      end;
    
      Function RandomChoose(Var N: Integer):String;
    
      var
      RandomNumber, Count: Integer;
      FileA: Textfile;
      Ok: Boolean;
      Phrase: String;
    
      begin
      randomize;
      RandomNumber:=Random(N)+1;
      Ok:=False;
    
      AssignFile(FileA, 'Myphrases.txt');
      reset(FileA);
    
      while Ok<>True
      do
      begin
    
      Readln(FileA, Phrase);
      Count:=Count+1;
    
      If Count = RandomNumber
      then
      begin
      Result:=Phrase;
      Ok:=True;
      end;
    
      end;
      end;
    
    
    
    { Main program block starts here }
    Begin
      PhraseHasBeenSet := False;
      Ptr3:=0;
      PhraseGuessed:=False;
      CountGos:=0;
    
      Repeat
        DisplayMenu;
        Write('Choice? ');
        Readln(Choice);
    
        Case Choice of
    
          '1':
    
            Begin
              NewPhrase := GetNewPhrase;
              SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
              PhraseHasBeenSet := True;
              ClrScr;
            End;
    
          '2':
    
            Begin
              If PhraseHasBeenSet = True
                Then
                  Begin
                    DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
    
                    repeat
                    NextGuessedLetter := GetNextLetterGuess;
                    Ptr:=0;
                    Ptr2:=0;
    
    
                    for count:= 1 to 26
                     do
                       begin
    
                        if NextGuessedLetter=LettersGuessedArray[Count]
                          then
                          begin
                          Ptr2:=Ptr2+1;
                          writeln('Sorry. Letter already Guessed!');
                          end;
                       end;
                       
                    Until Ptr2=0;
    
                    Ptr3:=Ptr3+1;
                    LettersGuessedArray[Ptr3]:=NextGuessedLetter;
    
    
                    For Index := 1 To Length(NewPhrase)
                      Do
                       begin
                        If NextGuessedLetter = NewPhrase[Index]
                          Then
                          GuessStatusArray[Index] := NextGuessedLetter
    
                          else
                          Ptr:=Ptr+1;
    
                        end;
    
                          If (Ptr= Length(Newphrase)) and (Countgos<9)
                          then
                          begin
                          Countgos:=Countgos+1;
                          writeln('Sorry. Tries left: ',9-Countgos)
                          end
                          else
                          writeln('Tries left: ',9-Countgos);
    
                    If CountGos<9
                    then
                    DisplayCurrentStatus(Length(NewPhrase), GuessStatusArray);
                    PhraseGuessed := AllLettersGuessedCorrectly(GuessStatusArray,NewPhrase);
                    If PhraseGuessed = True
                      Then Writeln('You have guessed correctly!');
                  End
                Else Writeln('The setter has not specified the word/phrase ..');
    
        End;
    
      '3':
      begin
    
       writeln('History of Letters: ');
       writeln;
    
       for Count2:=1 to 26
        do
         begin
           write(LettersGuessedArray[Count2]);
           write(' ');
         end;
    
       writeln;
      end;
    
    
     '4':
      begin
    
      writeln('Please Enter Phrase: ');
      readln(EntirePhrase);
      EntirePhrase:=UpperCase(EntirePhrase);//MAKE SURE TO UPPERCASE!
      Ptr4:=0;
    
      for count3:= 1 to Length(EntirePhrase) //LENGTH GUESSEDPHRASE...
      do
      begin
    
      if Entirephrase[Count3]=Newphrase[Count3]
      then
      Ptr4:=Ptr4+1
      else
      Ptr4:=Ptr4-1;
      end;
    
      If Ptr4=Length(Newphrase) // THEN LENGTH ORIGINAL PHRASE (OR VICE VERSA)
      then                      //OTHERWISE "MAN U" WOULD WORK IF PHRASE WAS "MAN UNITED"
    
      begin
      writeln('Congrats! You got it right!');
      PhraseGuessed:=True;
      end
    
      else
    
      CountGos:=CountGos+1;
      writeln('Sorry. You have: ',9-CountGos,' tries left');
    
    
      end;
    
    
    
     '5':
      begin
      NumberPhrases:=CountNumberPhrases;
      Newphrase:=RandomChoose(NumberPhrases);
      Phrasehasbeenset:=True;
      SetUpGuessStatusArray(NewPhrase, GuessStatusArray);
      end;
    
     '6':
      begin
    
      AssignFile(FileA,'Myphrases.txt');
      Append(FileA);
    
      Word1:=Getnewphrase;
    
      write(FileA,Word1);
    
      CloseFile(FileA);
    
      end;
    
    
     '7':
     begin
        If PhraseGuessed = False
          Then
            Begin
              Writeln('You have not completed this word/phrase...Press return to exit');
              Readln;
            End;
            end;
    
        else
    
        writeln('Sorry. A number between 1 and 6 must be entered');
        writeln;
    
      end//case
    
    
    
      until (Choice = '7') or (PhraseGuessed=True) or (Countgos=9);
    
      If CountGos=9
      then
      writeln('Your tries are up!');
    
      readln;
    
    End.
    Thanks

  5. #4
    2710 is offline Programmer
    Join Date
    Sep 2008
    Posts
    108
    Rep Power
    0

    Re: Win32CRT ClrScrn Function

    Wow! I found out! All I had to do was just put:

    DoneWinCRT;

    at the end! So simply.

    Thanks

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. function and function calls
    By jackson6612 in forum C and C++
    Replies: 10
    Last Post: 05-05-2011, 11:37 AM
  2. Replies: 1
    Last Post: 03-20-2011, 06:16 AM
  3. Replies: 3
    Last Post: 11-12-2010, 05:47 PM
  4. How do I use a variable in a function from a previous function?
    By system32 in forum JavaScript and CSS
    Replies: 2
    Last Post: 02-09-2010, 09:57 AM
  5. Function Help
    By Whitey in forum PHP Development
    Replies: 14
    Last Post: 04-23-2008, 09:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts