Solved

Text-tricks

Posted on 1998-01-14
153 Views
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
Question by:weinrj
• 4

LVL 2

Expert Comment

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);
End.

0

LVL 2

Expert Comment

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);
End.
0

LVL 2

Accepted Solution

omsec earned 20 total points
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);
End.

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

Author Comment

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

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"

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringinâ€¦
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.