Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Text-tricks

Posted on 1998-01-14
5
159 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

791 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