Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

VB6 RichTextBox question


azkanan
 Share

Recommended Posts

I'm trying to select and colour individual lines as they are printed into my RichTextBox, "GAME.menu_events". However, the selection keeps messing up.

The text-box itself handles different lines printed out onto it, depending what has happened since the player hit explore, or wait, or any other actions - for example, the player might find an item, run into a person and feel exhausted. All three are completely different calls handled per turn.

```

dim last_text as string

last_text = "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

GAME.menu_events.SelLength = Len(last_text)

GAME.menu_events.SelStart = Len(GAME.menu_events) - Len(last_text)

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.Font.Bold = True

GAME.menu_events.text = GAME.menu_events.text & vbNewLine & "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

```

Issue #1

The entire text box is being bolded (therefore affected?).

Issue #2

The colour is not changing.

Issue #3

From debugging, the SelLength = 0, whilst the "Len(last_text)" is reading out 102 - what the hell, right?
Link to comment
Share on other sites

```

GAME.menu_events.SelStart = Len(GAME.menu_events)

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.Font.Bold = False

GAME.menu_events.text = GAME.menu_events.text & vbNewLine & "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

GAME.menu_events.SelStart = Len(GAME.menu_events)

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.Font.Bold = True

GAME.menu_events.text = GAME.menu_events.text & vbNewLine & "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

```

Try that.
Link to comment
Share on other sites

```

dim last_text as string

last_text = "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

GAME.menu_events.SelStart = Len(GAME.menu_events)

GAME.menu_events.SelLength = Len(last_text)

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.Font.Bold = True

GAME.menu_events.text = GAME.menu_events.text & vbNewLine & "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

```
Link to comment
Share on other sites

```

Dim last_text As String

last_text = "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

GAME.menu_events.SelColor = vbBlack

GAME.menu_events.SelBold = False

GAME.menu_events.SelText = GAME.menu_events.SelText & vbNewLine & last_text

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.SelBold = True

GAME.menu_events.SelText = GAME.menu_events.SelText & vbNewLine & last_text

```

How about this?
Link to comment
Share on other sites

```

Dim last_text As String

last_text = "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

GAME.menu_events.SelStart = Len(GAME.menu_events) - Len(GAME.menu_events)

GAME.menu_events.SelLength = Len(last_text)

GAME.menu_events.SelColor = vbBlue

GAME.menu_events.Font.Bold = True

GAME.menu_events.text = GAME.menu_events.text & vbNewLine & "You sure do hope to come across Mr Blue again - he's an amazing dancer in that technicolour dreamcoat."

```

Taels works as well, but I don't know what you're going for. Compare the two.
Link to comment
Share on other sites

Problem solved by Jowd;

```

Call AddText("TEXT HERE.", RGB(150, 0, 255))

```
```

Public Sub AddText(ByVal Msg As String, ByVal Colour As Long, Optional IsBold As Boolean = False)

Dim S As String

S = vbNewLine & Msg

GAME.menu_events.SelStart = Len(GAME.menu_events.Text)

GAME.menu_events.SelColor = Colour

If IsBold Then

GAME.menu_events.SelBold = True

Else

GAME.menu_events.SelBold = False

End If

GAME.menu_events.SelText = S

GAME.menu_events.SelStart = Len(GAME.menu_events.Text) - 1

End Sub

```
Link to comment
Share on other sites

> Problem solved by Jowd;
>
> ```
>
> Call AddText("TEXT HERE.", RGB(150, 0, 255))
>
> ```
> ```
>
> Public Sub AddText(ByVal Msg As String, ByVal Colour As Long, Optional IsBold As Boolean = False)
>
> Dim S As String
>
> S = vbNewLine & Msg
>
> GAME.menu_events.SelStart = Len(GAME.menu_events.Text)
>
> GAME.menu_events.SelColor = Colour
>
> If IsBold Then
>
> GAME.menu_events.SelBold = True
>
> Else
>
> GAME.menu_events.SelBold = False
>
> End If
>
> GAME.menu_events.SelText = S
>
> GAME.menu_events.SelStart = Len(GAME.menu_events.Text) - 1
>
> End Sub
>
> ```

Well, and I helped get the ball rolling. ;p Honestly glad they added an AppendText method and cleaned up selection's in .NET.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...