Private Sub Command1_Click()
'use replace function- 8-10 seconds on 1,00,000;133mhz 'pentium this can be slow ; runs out of memory with '1,000,000 characters Dim ret Dim ct As New CTimer lastbutton = "Command1" ct.start Me.RichTextBox1.text = Replace$(Me.RichTextBox1.text, "*", "0") MsgBox ct.finish & "ms", , lastButtonCaption End Sub Private Sub Command5_Click() 'use mid$ Dim ct As New CTimer Dim pos As Long Dim r$ lastbutton = "Command5" ct.start ' r$ = RichTextBox1.text 'repeatedly find position of character then replace it pos = 0 Do pos = InStr(pos + 1, r$, "*") 'If MsgBox(pos, vbYesNo) = vbNo Then Exit Sub If pos <= 0 Then Exit Do Mid$(r$, pos, 1) = "0" Loop Me.RichTextBox1.text = r$ MsgBox ct.finish & "ms", , lastButtonCaption End Sub See the code for details. One interesting feature of this program is that it tracks the last button you pressed. If you click the View Code button, the program opens the Visual Basic source code and displays the code for the last button so you can see how it works. Also try the Replace button and the mid$ button (resetting the text between buttons). This compares using the Replace statement and Mid$ in a loop to replace a lot of occurrances of one character with another. Mid$ is more than 10 times faster. |