投稿日 | : 2005/03/21(Mon) 20:19 |
投稿者 | : Say |
Eメール | : |
URL | : |
タイトル | : Re: リッチテキストボックスを用いたターミナル |
> 受信文字が、すごい勢いで増えており文字列削除のスピードが
> 0.タイマー処理にて受信した文字をリッチテキストボックスに追記
Timerを使っている以上、せいぜい1行10msec程度だと思いますが、
その程度の速度で処理が間に合わないことはありませんが・・・。
そもそもリッチテキストボックス上で処理しようというのが間違いです。
処理は裏でやって、リッチテキストボックスは表示に徹するべきです。
ま、こんなかんじ
Option Explicit
Private Const BUFMAX As Long = 10240
Private Const LINEMAX As Long = 499
Dim buf(BUFMAX) As String
Dim buf2(LINEMAX) As String
Dim ptr As Long
Dim richidx As Long
Private Sub Command1_Click()
Command1.Enabled = False
Command2.Enabled = True
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Command1.Enabled = True
Command2.Enabled = False
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Dim i As Long
For i = 0 To BUFMAX
buf(i) = "[" & CStr(i + 1) & "] " & String(Int(Rnd() * 10) + 5, _
Chr(Asc("A") + Int(Rnd() * 26)))
Next
richidx = 0
ptr = 0
For i = ptr To ptr + LINEMAX
buf2(i) = buf(i)
Next
RichTextBox1(0).Visible = False
RichTextBox1(1).Visible = False
RichTextBox1(richidx).Text = Join(buf2, vbCrLf)
RichTextBox1(richidx).Visible = True
Command1.Caption = "START"
Command2.Caption = "STOP"
Command1.Enabled = True
Command2.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim richidx2 As Long, i As Long
richidx2 = (richidx + 1) Mod 2
ptr = ptr + 1
If ptr > BUFMAX - LINEMAX Then ptr = 0
For i = ptr To ptr + LINEMAX
buf2(i - ptr) = buf(i)
Next
RichTextBox1(richidx2).Text = Join(buf2, vbCrLf)
RichTextBox1(richidx).Visible = False
richidx = richidx2
RichTextBox1(richidx).Visible = True
End Sub