月刊プログラム!
VisualBasic For Excel
Vol_08
2001.MAY.30
Presented by kouta_y
感想等は掲示板、苦情はメールへ。
' 構造体の宣言は Type ステートメントを使う
Type MyStruct
Name As String
Age As Integer
End Type |
| Dim Status As MyStruct |
' モジュールレベル(グローバル領域)で宣言 ' プロージャレベルでは宣言出来ない ' 構造体の宣言(ユーザー定義型とも言う) Type MyStruct Name As String ' As から型の位置を揃えると見やすいカモ Age As Integer End Type Sub Sample() ' MyStruct型の変数の宣言 Dim Status As MyStruct '値の代入 Status.Name = "たろ" Status.Age = 22 'シートに反映 Cells(1, 1).Value = "名前は" Cells(2, 1).Value = "歳は" Cells(1, 2).Value = Status.Name Cells(2, 2).Value = Status.Age End Sub |

Type MyStruct
aaa As Integer
bbb As Byte
ccc As Long
ddd As String
eee As Boolean
End Type |

Sub Sample() Dim a As MyStruct ' アドレスとメンバの型の領域を表示 Debug.Print VarPtr(a.aaa); Len(a.aaa) Debug.Print VarPtr(a.bbb); Len(a.bbb) Debug.Print VarPtr(a.ccc); Len(a.ccc) Debug.Print VarPtr(a.ddd); Len(a.ddd) Debug.Print VarPtr(a.eee); Len(a.eee) End Sub |