Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-07-02
8
Medium Priority
?
777 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
[X]
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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

705 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