Solved

Overwrite the contents in the rich text box while editing(in VB6.0)

Posted on 2001-07-02
8
760 Views
Last Modified: 2010-05-18
I am using a rich text box.
Rich text box displays the contents from a text file.
I want user to write in the rich text box but no new character. Already displayed content should be over written and if he types correctly then it's color should be blue otherwise red.
For example
In text box following contentx are displayed

ad sdf dfg

user types

ad dfggdfg

now first two characters ad are correctly types so they should appear in blue.
At 4th position instead of 's' he types 'd' so 'd' should be displayed in red and it should over write the 's'.
Now if user presses back space then original contents should appear
How to perform this?
Give the logic
I want to do this in VB6.0
0
Comment
Question by:rajiv
8 Comments
 
LVL 11

Expert Comment

by:Otana
ID: 6244399
Use a second, invisible Rich TextBox in which you keep the original content.

Use the keypress event, check the location of your cursor, compare to character in original content.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6244469
This should do it for you, the comparison method as otana suggest is the way to go, in this case I am storing the .Text value in the .Tag property of the rtb in the form_load, you could do this wherever appropriate.

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case Asc("A") To Asc("Z"), Asc("a") To Asc("z"), Asc("0") To Asc("9"), 32
        With RichTextBox1
            CurrentChar = Chr(KeyCode)
            If Shift = 0 Then CurrentChar = LCase(CurrentChar)
            If CurrentChar = Mid(.Tag, .SelStart + 1, 1) Then
                .SelLength = 1
                .SelColor = vbBlue
                .SelText = IIf(.SelStart >= Len(.Tag), "", CurrentChar)
            Else
                .SelLength = 1
                .SelColor = vbRed
                .SelText = IIf(.SelStart >= Len(.Tag), "", CurrentChar)
            End If
        End With
        KeyCode = 0
    Case 8
        With RichTextBox1
            .SelStart = .SelStart - 1
            .SelLength = 1
            .SelColor = vbBlack
            .SelText = Mid(.Tag, .SelStart + 1, 1)
            .SelStart = .SelStart - 1
        End With
        KeyCode = 0
    Case 33 To 40
    Case Else
        KeyCode = 0
    End Select
End Sub
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6525942
TimCottee,

I tried your code and was unable to get it to work.

I found that .Tag was always "" as a value was never set to it.

Is there additional code that you forgot to post?

Wileecoy.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6526429
Wileecoy:

>> in this case I am
storing the .Text value in the .Tag property of the rtb in the form_load

I guess this is the bit you missed!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Expert Comment

by:wileecoy
ID: 6528483
oh - you mean all those words above the code?? lol.
0
 
LVL 4

Expert Comment

by:wileecoy
ID: 6528572
Excellent - it works now! - mostly.

I am trying to code in "," and "-".

I'm not sure if rajiv will have a need for these - I have no need, but would make coding more complete.

Let us know rajiv.

This solution looks good.

Wileecoy.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140053
Hi rajiv@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept TimCottee's comment(s) as an answer.

rajiv@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
ID: 7178803
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now