Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2001-07-02
8
765 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 115
I need help embedding an image as HTML in my vb.net application 3 73
vbModal 12 57
VBA: copy range dynamically based on config sheet v2 3 48
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

860 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