Solved

Text manipulation help ...

Posted on 2003-10-27
7
182 Views
Last Modified: 2010-05-03
A user started a session and at the halfway , he want to remove the timestamp , it'll be

Output :
[3:00:00PM ] blahblah
[3:00:01PM ] dsadsa
dsdsa
dasdsadsa

How can i do that
Output :

blahblah
dsadsa
dsdsa
dasdsadsa

??

My original code is  :

Private Sub StatusLog(What As String)
If TimeStampValue = 1 Then   '<<< Timestamp enabled
    With txtStatus
        .SelLength = 0
        .SelStart = Len(txtStatus.Text)
        .SelColor = StatusTimeColor
        .SelText = "[ " & Time() & " ]  "
        .SelColor = StatusMainTextColor
        .SelText = What & vbCrLf
    End With
Else       'Timestamp disabled

With txtStatus
        .SelLength = 0
        .SelStart = Len(txtStatus.Text)
        .SelColor = StatusMainTextColor
        .SelText = What & vbCrLf
    End With

End If

End Sub

But it doesnt override the previous text.


-----------------

0
Comment
Question by:vbaddictor
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Expert Comment

by:_agj_
ID: 9626652
what exactly do u want. Clearer plz.

"But it doesnt override the previous text."  ---> meaning?

the code looks ok, btw.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9626658
It appears that you are using Richtextbox control, right?, then you need to use the specific funtions to work with RTF formated text, it appears that you are using simple text methods.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9626661
To be more specific:
.selRTF
.textRTF
i think.
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 86

Expert Comment

by:Mike Tomlinson
ID: 9627716
With a richtextbox, the .SelText function CHANGES whatever is currently selected to the value you pass it.  If nothing is currently selected, then the .SelText function inserts its text into the richtextbox where the insert point currently is.  

To remove the time stamps, you will need to walk the contents of your box, using .SelStart and .SelLength to pick out the time stamp portions and take them out using .SelText ="".

Now it appears that the your users will be able to turn time stamps on/off at will.
A major design decision will have to be made:  

---> If time stamps are initially on, then turned off, and then later turned back on....should the original time stamps be restored?

To accomplish this, you will have to "store" the time stamps for later retrieval.

One way to do this would be by keeping your time stamps w/ messages in a collection and then rebuild the entire chat history with the appropriate colors.
You could also cheat and use two richtextboxes, one with timestamps and one without.  You can then simulate turning time stamps on/off by making one box visible while the other is not and then switching their visibility states.

I believe you also have some code that allows the user to change the stampcolor and msgcolor at will no?  If you do, then that function needs to be modified to take into account the fact that the time stamp may or may not be present in the richtextbox.

Anyway, I do ramble on....let us know how you want the chat app to behave and we can help you accomplish that.

Cheers
0
 

Author Comment

by:vbaddictor
ID: 9628016
Idle_Mind , ya , that's the problem ... the main problem is i dunno how to restore .. when user turn it on then off then on again .. sigh .. can u pelase help me ?
0
 

Author Comment

by:vbaddictor
ID: 9628040
oh ic ... Idle_Mind .. using 2 rtbs might be a good solution ..
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 9628354
If you go with the two richtextbox method, then name your second richtextbox txtStatus2, set it's visible property to false, and place it right on top of the first richtextbox.

Then you can change your code to this:
Private Sub StatusLog(What As String)
    With txtStatus
            .SelLength = 0
            .SelStart = Len(txtStatus.Text)
            .SelColor = StatusTimeColor
            .SelText = "[ " & Time() & " ]  "
            .SelColor = StatusMainTextColor
            .SelText = What & vbCrLf
    End With
    With txtstatus2
            .SelLength = 0
            .SelStart = Len(txtstatus2.Text)
            .SelColor = StatusMainTextColor
            .SelText = What & vbCrLf
    End With
End Sub

And toggle your stamps on/off by passing true false to this function:
Private Function showTimeStamps(showStamps As Boolean)
    If showStamps Then
        txtstatus2.Visible = False
        txtStatus.Visible = True
    Else
        txtStatus.Visible = False
        txtstatus2.Visible = True
    End If
End Function
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

710 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