VB6.0用掲示板の過去のログ(No.2)−VBレスキュー(花ちゃん)
[記事リスト] [新規投稿] [新着記事] [ワード検索] [管理用]

投稿日: 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


- 関連一覧ツリー (★ をクリックするとツリー全体を一括表示します)

- 返信フォーム (この記事に返信する場合は下記フォームから投稿して下さい)

- VBレスキュー(花ちゃん) - - Web Forum -