Not a Member Yet,
Click here to Register

ID: 467
Viewed: 3846
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

The subroutines I have created allow you
to augment the text by adding special
effects such as bold, underline, italics
and one of three colours (Red, Blue or
Green).

The effects are enabled by adding
control codes to the text to be displayed. These codes consist of a tilde (~) followed by a one or two character
modifier. The current list is:

~B Toggles bold on and off
~I Toggles italics on and off
~U Toggles underline on and off
~CR Switches to red text
~CB Switches to blue text
~CG Switches to green text
~CN Switches back to normal (black) text.

The text is displayed in a picture control and will be word wrapped at the edge of the control.

The format of the subroutine call is:

DisplayText picText, sText

Where "picText" is the name of the picture control you wish to display the text in and "sText" is the text string to
display. For the purposes of the sample code, the text to be displayed is defined in the Form_Load procedure.

Highlight all by clicking in box
<!---Declaration--->
none

Highlight All
<!---Code--->
Sub DisplayText (picText As Control, sText As String)

'==========================================================================

' Displays text in the picture box, word wrapping at the relevant points.

'==========================================================================

Dim sString As String
Dim sWords As String
Dim nWordLen As Single
Dim nPos As Integer


'*********************************************************************

'* Copy the input string and remove extraneous spaces

'*********************************************************************

sString = Trim$(sText)


'*********************************************************************

'* Reset the picture box state

'*********************************************************************

picText.Cls
picText.CurrentX = 0
picText.CurrentY = 0
picText.FontBold = False
picText.FontItalic = False
picText.FontUnderline = False
picText.AutoRedraw = True


'*********************************************************************

'* If there are no formatting codes, just display the text

'*********************************************************************

nPos = InStr(sString, "~")


'******************************************************************

'* Loop printing text until we run out of control characters

'******************************************************************

Do While nPos > 0


'******************************************************************

'* Extract any leading text

'******************************************************************

sWords = Left$(sString, nPos - 1)
sString = Mid$(sString, Len(sWords) + 1)


'******************************************************************

'* If there is leading text, display it

'******************************************************************

If Len(sWords) > 0 Then DisplayTextBlock picText, sWords

'******************************************************************

'* Set the required formatting attribute

'******************************************************************

sWords = Left$(sString, 2)
sString = Mid$(sString, 3)

Select Case UCase$(sWords)
Case "~C"

'******************************************************************

'* Colour change : the next colour indicates which

'* colour we want to switch to; r=red, g=green, b=blue,

'* n=normal(black)

'******************************************************************

sWords = Left$(sString, 1)
sString = Mid$(sString, 2)


'***************************************************************

'* Check which colour they want

'***************************************************************

Select Case UCase$(sWords)

Case "R"

picText.ForeColor = RGB(255, 0, 0)

Case "G"

picText.ForeColor = RGB(0, 255, 0)

Case "B"

picText.ForeColor = RGB(0, 0, 255)

Case "N"

picText.ForeColor = RGB(0, 0, 0)

End Select

Case "~B"

'***************************************************************

'* Toggle the setting of the bold flag

'***************************************************************

picText.FontBold = Not picText.FontBold

Case "~U"

'***************************************************************

'* Toggle the setting of the underline flag

'***************************************************************

picText.FontUnderline = Not picText.FontUnderline

Case "~I"

'***************************************************************

'* Toggle the setting of the italics flag

'***************************************************************

picText.FontItalic = Not picText.FontItalic

End Select



'******************************************************************

'* Now we loop to do the next one

'******************************************************************

nPos = InStr(sString, "~")
Loop



'*********************************************************************

'* Display whats left

'*********************************************************************

If Len(sString) > 0 Then DisplayTextBlock picText, sString

End Sub

Sub DisplayTextBlock (picText As Control, sText As String)

'==========================================================================

' Displays text in the picture box, word wrapping at the relevant points.

'==========================================================================

Dim sString As String
Dim sWord As String
Dim nWordLen As Single
Dim nSpace As Integer

'*********************************************************************

'* Stuff a trailing space in the end of a stripped string. This gives

'* an end point for the loop.

'*********************************************************************

sString = sText

'*********************************************************************

'* Loop while there are words to wrap.

'*********************************************************************

Do While Len(sString) > 0
nSpace = InStr(2, sString, " ")
If nSpace = 0 Then nSpace = Len(sString)

'******************************************************************

'* Get next word and determine its size

'******************************************************************

sWord = Left$(sString, nSpace)
nWordLen = picText.TextWidth(sWord)


'******************************************************************

'* See if it will fit on the screen. If not, break the line up.

'******************************************************************

If (picText.CurrentX + nWordLen) > picText.Width Then

'***************************************************************

'* Insert a line break.

'***************************************************************

picText.Print ""

'***************************************************************

'* If we have leading spaces, drop them

'***************************************************************

If Right$(sWord, 1) = " " Then
sWord = Trim$(sWord) & " "
Else
sWord = Trim$(sWord)
End If
End If

'******************************************************************

'* Display the word.

'******************************************************************

If Len(Trim$(sWord)) > 0 Then picText.Print sWord;



'******************************************************************

'* Strip word out of string and continue loop.

'******************************************************************

sString = Mid$(sString, Len(sWord) + 1)
Loop

End Sub;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!