| VB.NET での構造体の宣言 | |
|
001 002 003 004 005 006 007 008 |
Structure Rect Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer End Structure |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 |
Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 |
' 構造体型変数の宣言 Dim r As Rect ' 各メンバに値を設定する場合 r.Left = 0 r.Top = 0 r.Right = 320 r.Bottom = 240 |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 |
Structure Rect Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer Sub SetRect(ByVal left As Integer, ByVal top As Integer, ByVal right As Integer, ByVal bottom As Integer) Me.Left = left Me.Top = top Me.Right = right Me.Bottom = bottom End Sub End Structure Module MainModule Sub Main() ' 構造体型変数の宣言 Dim r As Rect ' 各メンバに値を設定する r.SetRect(0, 0, 320, 240) End Sub End Module |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 |
Sub SetRect(ByVal l As Integer, ByVal t As Integer, ByVal r As Integer, ByVal b As Integer) Left = l Top = t Right = r Bottom = b End Sub |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 |
' 長方形の幅を返すメソッド Function GetWidth() As Integer Return Right - Left End Function ' 長方形の高さを返すメソッド Function GetHeight() As Integer Return Bottom - Top End Function |
| VB6以前 でのユーザー定義型の宣言 | |
|
001 002 003 004 005 006 007 008 009 |
Property プロパティ名() As 型 Get End Get Set(ByVal Value As 型) End Set End Property |
| 読み取り専用プロパティ | |
|
001 002 003 004 005 |
ReadOnly Property プロパティ名() As 型 Get End Get End Property |
| 書き込み専用プロパティ | |
|
001 002 003 004 005 |
WriteOnly Property プロパティ名() As 型 Set(ByVal Value As Integer) End Set End Property |
|
001 002 003 004 005 006 007 008 009 010 011 |
Private m_Width As Integer Property Width() As Integer Get Return m_Width End Get Set(ByVal Value As Integer) m_Width = Value End Set End Property |
|
001 002 003 004 005 006 007 008 009 010 011 |
ReadOnly Property Width() As Integer Get Return Right - Left End Get End Property ReadOnly Property Height() As Integer Get Return Bottom - Top End Get End Property |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 |
Structure Rect Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer Sub SetRect(ByVal l As Integer, ByVal t As Integer, _ ByVal r As Integer, ByVal b As Integer) Left = l Top = t Right = r Bottom = b End Sub ReadOnly Property Width() As Integer Get Return Right - Left End Get End Property ReadOnly Property Height() As Integer Get Return Bottom - Top End Get End Property End Structure Module MainModule Sub Main() ' 構造体型変数の宣言 Dim r As Rect ' 各メンバに値を設定する r.SetRect(160, 120, 640, 480) Console.WriteLine("Width: {0}, Height: {1}", r.Width, r.Height) End Sub End Module |
| 出力結果 | |
Width: 480, Height: 360 | |
|
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 |
Structure Rect Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer Sub New(ByVal l As Integer, ByVal t As Integer, ByVal r As Integer, ByVal b As Integer) Left = l Top = t Right = r Bottom = b End Sub . . 以下同じ . . End Structure |
|
001 002 003 004 005 006 |
' コンストラクタを使用した例 Dim r As New Rect(160, 120, 640, 480) ' 次のコードは上のコードと等価です Dim r As Rect r.SetRect(160, 120, 640, 480) |