Click here to Skip to main content
15,902,777 members
Articles / Programming Languages / VBScript
Article

VBScript version of Figlet

Rate me:
Please Sign up or sign in to vote.
4.54/5 (5 votes)
26 Nov 2008CPOL2 min read 30.9K   361   8   10
A complete VBScript implementation of FIGlet

Introduction

This program is a VBScript implementation of a popular freeware FIGlet. It is a program that generates text banners in a variety of typefaces comprised of letters made up of smaller ASCII characters.

Background

In Spring 1991 inspired by the e-mail signature of Frank Sheeran and goaded on by Ian Chai, Glenn Chappell wrote a nifty little 170-line 'C' program, which he called 'newban'. This very first version circulated around the net for a couple of years. It had one font, which included only lower-case letters.

In early 1993, Ian decided 'newban' was due for a few changes. And 7-months later they came up with a completely re-written version of having 888 lines of 'C' code. This was figlet 2.0, the first real release. It had 13 fonts.

Then came the new release figlet 2.1 immediately followed by 2.1.1. This last weighed in at 1314 lines, and had over 60 fonts.

Figlet Illustrations

So how does figlet look. Here are a couple of samples:

DOOM

 ______   _           _          _
|  ____| (_)         | |        | |
| |__     _    __ _  | |   ___  | |_
|  __|   | |  / _` | | |  / _ \ | __|
| |      | | | (_| | | | |  __/ | |_
|_|      |_|  \__, | |_|  \___|  \__|
               __/ |
              |___/

LARRY3D

 ____                      ___               __
/\  _`\   __              /\_ \             /\ \__
\ \ \L\_\/\_\      __     \//\ \       __   \ \ ,_\
 \ \  _\/\/\ \   /'_ `\     \ \ \    /'__`\  \ \ \/
  \ \ \/  \ \ \ /\ \L\ \     \_\ \_ /\  __/   \ \ \_
   \ \_\   \ \_\\ \____ \    /\____\\ \____\   \ \__\
    \/_/    \/_/ \/___L\ \   \/____/ \/____/    \/__/
                   /\____/
                   \_/__/

Usage

To use this program all you need is Windows Scripting Runtime. I have tested and developed this version under 5.6. On the command prompt, you have to type the following command:

D:\TOOLS\FIGLET>cscript //Nologo Figlet.vbs /text:[TEXT] /font:[Figlet Font Name]

Where:

  • [TEXT] - The text you want to convert
  • [Figlet Font Name] - The name of the figlet font

The name of the figlet font is the name of the font file without '.flf' extension. You can find many fonts under the FONTS folder.

Notes

You need to run this program from the same folder in which Figlet.vbs file is present as the font files are loaded from the FONTS folder located under the same folder.

Limitations

  1. It does not support the more advanced features like kerning or smushing.

References

  1. Figlet home page
  2. Figlet font specification

History

  • 26th November, 2008 - First release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Freelancer
India India
I am a software professional with over 20 years of commercial business applications design and development experience.

My programming experience includes Java, Spring, .NET, Classic VB & ASP, Scripting, Power Builder, PHP, Magic & far far ago FoxPro, C, Assembly and COBOL.

From last 11 years I am mostly working with Java Technology. I am currently available to take up new assignments.

Comments and Discussions

 
QuestionFiglet Pin
la conic2-Mar-24 19:18
la conic2-Mar-24 19:18 
QuestionVisual Basic 6 Pin
s0u126-Sep-20 17:19
s0u126-Sep-20 17:19 
AnswerRe: Visual Basic 6 Pin
s0u127-Sep-20 5:25
s0u127-Sep-20 5:25 
GeneralRe: Visual Basic 6 Pin
Richard MacCutchan1-Oct-20 23:10
mveRichard MacCutchan1-Oct-20 23:10 
GeneralRe: Visual Basic 6 Pin
s0u14-Oct-20 16:17
s0u14-Oct-20 16:17 
AnswerRe: Visual Basic 6 Pin
D_Walla16-Apr-21 20:52
D_Walla16-Apr-21 20:52 
GeneralJust what I needed, thanks. Here's a quick port to vb.net. Pin
Member 1101556015-Aug-14 13:58
Member 1101556015-Aug-14 13:58 
VB
Public Class Figlet

    '   _____   _           _          _   
    '  |  ___| (_)   __ _  | |   ___  | |_ 
    '  | |_    | |  / _` | | |  / _ \ | __|
    '  |  _|   | | | (_| | | | |  __/ | |_ 
    '  |_|     |_|  \__, | |_|  \___|  \__|
    '               |___/                  

    'Purpose:   draw banner text using Figlet font information
    'written:   cf 16.08.2014 (Charles Finn)
    'rights:    public domain, adapted from http://www.codeproject.com/KB/vbscript/FigletVBS/FIGLET.zip by Prasad Khandekar, 26 Nov 2008

    Private _HardBlank As String
    Private _Height As Integer
    Private _Baseline As Integer
    Private _MaxLen As Integer
    Private _OldLayout As Integer
    Private _CommentLines As Integer
    Private _PrintDirection As Integer
    Private _FullLayout As Integer
    Private _CodeTagCount As Integer
    Private _fontData() As String

    'Characters to insert ahead of line
    Private m_Prefix As String = String.Empty

    Public Sub New(ByVal FigletFontFilename As String)

        LoadFont(FigletFontFilename)

    End Sub

    Public Function Convert(ByVal theText As String) As String()
        'given string, return a set of lines

        Dim result = New List(Of String)

        For cntr As Integer = 1 To _Height
            Dim oneline = New System.Text.StringBuilder(200)
            oneline.Append(m_Prefix)

            For idx As Integer = 1 To theText.Length
                Dim oneChar As Char = CChar(Mid(theText, idx, 1))
                oneline.Append(GetCharacter(oneChar, cntr))
            Next

            result.Add(oneline.ToString)

        Next


        Return result.ToArray

    End Function


    Public Property Prefix() As String
        Get
            Return m_Prefix
        End Get
        Set(ByVal value As String)
            m_Prefix = value
        End Set
    End Property


    Private Sub LoadFont(ByVal fontFile As String)

        Using rdr As IO.StreamReader = New IO.StreamReader(fontFile)
            Dim lines = New List(Of String)

            Do While rdr.Peek <> -1
                lines.Add(rdr.ReadLine)
            Loop

            _fontData = lines.ToArray
        End Using


        Dim arrTmp As String() = Split(_fontData(0), " ", -1)
        Dim uBnd As Integer = UBound(arrTmp)

        Dim strTmp As String = arrTmp(0)
        Dim Signature As String = Left(strTmp, Len(strTmp) - 1)
        _HardBlank = Right(strTmp, 1)
        _Height = CInt(arrTmp(1))
        _Baseline = CInt(arrTmp(2))
        _MaxLen = CInt(arrTmp(3))
        _OldLayout = CInt(arrTmp(4))
        _CommentLines = CInt(arrTmp(5))


        If (uBnd > 5) Then _PrintDirection = CInt(arrTmp(6))
        If (uBnd > 6) Then _FullLayout = CInt(arrTmp(7))
        If (uBnd > 7) Then _CodeTagCount = CInt(arrTmp(8))

        If (Signature <> "flf2a") Then
            Err.Raise(vbObjectError + 1000, "LoadFont", "Font " & fontFile & " is not a Figley font!")
        End If

    End Sub

    Private Function GetCharacter(ByVal oneChar As Char, ByVal intLine As Integer) As String

        Dim ascii As Integer = Asc(oneChar)
        Dim start As Integer = _CommentLines + (ascii - 32) * _Height

        Dim temp As String = _fontData(start + intLine)
        temp = temp.Replace("@", "")
        temp = temp.Replace(_HardBlank, " ")

        Return temp

    End Function

End Class

GeneralRe: Just what I needed, thanks. Here's a quick port to vb.net. Pin
Prasad Khandekar17-Aug-14 9:33
professionalPrasad Khandekar17-Aug-14 9:33 
GeneralHere's a quick port to Powershell Pin
g_p_l30-Nov-16 7:52
g_p_l30-Nov-16 7:52 
GeneralGreat Work Pin
Irwan Hassan3-Dec-08 15:44
Irwan Hassan3-Dec-08 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.