Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2001-07-02
8
Medium Priority
?
778 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Accepted Solution

by:
TimCottee earned 400 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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

783 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