Solved

Text-tricks

Posted on 1998-01-14
5
160 Views
Last Modified: 2010-04-16
a pas prog that will do this

display a message that will display colors 1 - 15 randomly flashing
Procedure or Function, which ever is better

how to use this subprogram within the main program.

DispMsg('Welcome!,c or r');  or something similar

can be Consecative color #'s [1..15] as one option or Random as an other.
///an other option is posistioning of the message / shall it be centered?

or kewl stuff, such as gradients, shades of green flyby char by char

such as [W][E][L][C][O][M][E][!]
THE W WILL BE VERY LIGHT GREEN AND THE ! WILL BE BRIGHTEST, THEN THE DARK
CHARACTER WILL GET LIGHTER ONE BY ONE, AS THE COLORS ARE MOVING FROM CHAR
TO CHAR
0
Comment
Question by:weinrj
  • 4
5 Comments
 
LVL 2

Expert Comment

by:omsec
ID: 1217120
Hi there !

Below, i wrote a procedure that does that job for you. You can easily use another algorythm to set the colors...

The routine expects 3 parameters :

MSG : STRING - The sting that you wanna write
X,Y : BYTE   - The X/Y - Postion where you wanna place the MSG

Program Test;

Uses
  Crt;

Procedure DispMSG(Msg : String; X, Y : Byte);

Var
  L,
  C     : Byte;

Begin
  C := 1;
  For L := 1 To Length(MSG) Do
    Begin
      TextColor(C);
      Write((MSG[C]));
      Inc(C);
      If C = L Then
        C := 15;
    End;
End;

Begin
  ClrScr;
  DispMSG('welcome!', 10, 10);
  ReadLn;
End.

0
 
LVL 2

Expert Comment

by:omsec
ID: 1217121
Hi there !

Below, i wrote a procedure that does that job for you. You can easily use another algorythm to set the colors...

The routine expects 3 parameters :

MSG : STRING - The sting that you wanna write
X,Y : BYTE - The X/Y - Postion where you wanna place the MSG

Program Test;

Uses
Crt;

Procedure DispMSG(Msg : String; X, Y : Byte);

Var
L,
C : Byte;

Begin
C := 1;
For L := 1 To Length(MSG) Do
 Begin
 TextColor(C);
 Write((MSG[C]));
 Inc(C);
 If C = L Then
 C := 15;
 End;
End;

Begin
ClrScr;
DispMSG('welcome!', 10, 10);
ReadLn;
End.
0
 
LVL 2

Accepted Solution

by:
omsec earned 20 total points
ID: 1217122
Hi there !

Below, i wrote a procedure that does that job for you. You can easily use another algorythm to set the colors...

The routine expects 3 parameters :

MSG : STRING - The sting that you wanna write
X,Y : BYTE - The X/Y - Postion where you wanna place the MSG

Program Test;

Uses
Crt;

Procedure DispMSG(Msg : String; X, Y : Byte);

Var
L,
C : Byte;

Begin
C := 1;
For L := 1 To Length(MSG) Do
 Begin
 TextColor(C);
 Write((MSG[C]));
 Inc(C);
 If C = L Then
 C := 15;
 End;
End;

Begin
ClrScr;
DispMSG('welcome!', 10, 10);
ReadLn;
End.

PS : Damn **** - i clicked on the wrong button - heheh
0
 

Author Comment

by:weinrj
ID: 1217123
thank you very much!!  

PS- i get a problem sometimes where an unknown charactor displays
on the screen and nowhere in the source.

how come this happens?
0
 
LVL 2

Expert Comment

by:omsec
ID: 1217124
Hello out there !

Fist, sorry for this late answer, but usually i don't look at questions in the archive.

I wrote you here a more improved version of that DispMSG - Procedure. I saw u wrote "procedure or function, wich ever is better" that seems you don't really know the different between a procedure and a function. Well, the job of a procedure is to do a program part. it executes that part and at its end if changes back to the main program code. A function does someting (that can of course be a program part) and returns you a value, so it calculates someting. For example you cannot declare a something like this :

Function WriteText;

That would bring you an error from the compiler. For this you have to use the key word Procedure

Procedure WriteTexr; {= ok}

The job of a function would be this :

Function FileExist(FileName : String) : Boolean;

A function doesnt have to expect a parameter but usually its needed. You see this function would return TRUE (1) in the format of an 1-Bit Boolean - Variable. The whole code were :

Function FileExists(FileName : String) : Boolean;

Var
  WantedFile : File;  {needed file - variable}

Begin
Begin
  {$I-} {turn auto i/o - checkl off}
    Assign(WantedFile, FileName);
    Reset(WantedFile);
    Close(WantedFile);
  {$I+} {turn it back on}
  FileExists := (IoResult = 0) and (FileName <> '');
End;

ok, this about the Procedure/Function - Stuff...

Below is the source code of the improved color - algorytm :

Procedure DispMSG(Message : String; X, Y : Byte);

Var
  L,
  C           : Byte;

Begin
  C := 1;
  Gotoxy(X, Y);
  For L := 1 To Length(Message) Do
    Begin
      TextColor(C);
      Write((Message[L]));
      Inc(C);
      If C = 15 Then
        C := 1;
    End;
End;

I removed a bug there. Its now able to write long strings too.
As you can see at line "If C = 15 Then C := 1", this means if C
has the code 15 (White) set it back to 1 (Blue) and dont write a white char. I disabled white-chars cos they are very bright. If you wish to use write char color, just replace the "15" with a "16" and the line will look like this : "If C = 16 Then C := 1"

About your last problem...

Hm.. i dont really see what you mean. In Borland's String - Format (An array of chars) can you use all of the 255 characters of the extended char-set from IBM/MS - Standard. The Pascal - Compiler doesnt allow such chars in the source code, only in strings to write or work with.

I hope this could help :)

Greets, Omsec
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question