VB.NET覚書

VB.NETの覚書
[個人メモ] [仕事メモ] [アイデア] [Ruby]
[TIPS] [対応表] [コメント書き方] [.NET Tips] [VB中学校] [VB.NET の入門サイト] [VB.NET コーディング標準 ] [VBレスキュー] [NonSoft]

2009-04-06

Queueの使い方

Public Class Form1

Private queue As Queue

Private count As Integer

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'キュー生成

queue = New Queue(10)

count = 0

End Sub

'Enqueueボタン処理

Private Sub EnququeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnququeBtn.Click

'Enqueue

queue.Enqueue("Item" + count.ToString())

'ListBoxにQueueを配置

Me.ListBox1.DataSource = queue.ToArray()

count += 1

End Sub

'Dequeueボタン処理

Private Sub DequeueBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DequeueBtn.Click

'Dequeue

queue.Dequeue()

'ListBoxにQueueを配置

Me.ListBox1.DataSource = queue.ToArray()

End Sub

End Class

Queue(キュー)@VB.Netのお勉強

ミリ秒の計測

Public Class Form1

    Private dt As DateTime

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dt = DateTime.Now
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Debug.Print((DateTime.Now - dt).TotalMilliseconds.ToString)
    End Sub
End Class

HTTP読み出し

Imports System.Net

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
        ' HTTPサーバーへ接続する
        Dim client As New WebClient
        Try
            ' HTTPサーバーへ接続しストリームを取得する
            Dim stream As System.IO.Stream = _
                client.OpenRead(TextBox1.Text)
            ' テキストボックスへ結果を書き出す
            Dim reader As New System.IO.StreamReader(stream)
            TextBox2.Text = reader.ReadToEnd()
            reader.Close()
            stream.Close()
        Catch ex As WebException
            ' URLが不正の場合は例外が発生する
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
トラックバック - http://sub.g.hatena.ne.jp/garyo/20090406