Type 自定义类型名 元素名[(下标)] As 类型名 …… 元素名[(下标)] As 类型名 End Type
元素名:表示自定义类型中的一个成员
下标(可选):表示是数组
类型名:为标准类型
例:定义一个学生信息的自定义类型: Type studtype No As Integer ’ 定义学号 Name As String*10 ’ 定义姓名 Sex As String*2 ’ 定义性别 Mark(1 TO 4) As Single ’ 定义4门课程的成绩 Total As Single ’ 定义总分 End Type
例如: Dim student As studtype, mystud As studtype 自定义类型中元素的表示方法是:变量名 . 元素名 如:student.name student.mark(4) 为了简单起见,可以用With …… End With 语句进行简化。 例: With student .no=99001 .name="" .sex="" .total=0 for I=1 to 4 .mark(I)=int(rnd*101) ’随机产生0 - 100之间的分数 .total=.total .may(I) next I End With Mystud=student ’ 同种自定义类型变量可以直接赋值