VB编程问题!!自定义数据类型
要求是这样的:利用自定义数据类型建立10个学生数据,并实现以下功能:根据学号查找根据姓名查找各门课程成绩的平均值、最大值、最小值查找(假设三门课程)各个学生成绩总分的排序...
要求是这样的:利用自定义数据类型建立10个学生数据,并实现以下功能:
根据学号查找
根据姓名查找
各门课程成绩的平均值、最大值、最小值查找(假设三门课程)
各个学生成绩总分的排序
我这样编~但是运行的时候第一行就有问题~说在私有对象模块中不能定义PUBLIC的用户定义类型~但是这段我写在通用声明段里的~为什么会这样呢?
Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
Dim number As Integer
Dim name1 As Integer
Dim i As Integer
--------------------------------
Public Sub Form_Load()
Dim stud(1 To 10) As studtype
For i = 1 To 10
With stud(i)
.no = i
.total = 0
.max = 0
.min = 100
For j = 1 To 3
.mark(j) = Int(Rnd * 101)
.total = total + mark(j)
If mark(j) > max Then
.max = mark(j)
End If
If mark(j) < min Then
.min = mark(j)
End If
Next j
.aver = total / 3
End Sub
---------------------------
Private Sub Command1_Click()
number = Text1.Text
For i = 1 To 10
If stud(i).no = number Then
Picture1.Print stud(i).mark(1)
Picture1.Print stud(i).mark(2)
Picture1.Print stud(i).mark(3)
Picture1.Print stud(i).aver
Picture1.Print stud(i).max
Picture1.Print stud(i).min
End If
Next i
End Sub 展开
根据学号查找
根据姓名查找
各门课程成绩的平均值、最大值、最小值查找(假设三门课程)
各个学生成绩总分的排序
我这样编~但是运行的时候第一行就有问题~说在私有对象模块中不能定义PUBLIC的用户定义类型~但是这段我写在通用声明段里的~为什么会这样呢?
Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
Dim number As Integer
Dim name1 As Integer
Dim i As Integer
--------------------------------
Public Sub Form_Load()
Dim stud(1 To 10) As studtype
For i = 1 To 10
With stud(i)
.no = i
.total = 0
.max = 0
.min = 100
For j = 1 To 3
.mark(j) = Int(Rnd * 101)
.total = total + mark(j)
If mark(j) > max Then
.max = mark(j)
End If
If mark(j) < min Then
.min = mark(j)
End If
Next j
.aver = total / 3
End Sub
---------------------------
Private Sub Command1_Click()
number = Text1.Text
For i = 1 To 10
If stud(i).no = number Then
Picture1.Print stud(i).mark(1)
Picture1.Print stud(i).mark(2)
Picture1.Print stud(i).mark(3)
Picture1.Print stud(i).aver
Picture1.Print stud(i).max
Picture1.Print stud(i).min
End If
Next i
End Sub 展开
4个回答
展开全部
试着加上private 关键字:
Private Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
(如果 想用实现公有
则新建一个模块
里面写:
Public Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
)
Private Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
(如果 想用实现公有
则新建一个模块
里面写:
Public Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Type 定义要写在Module模块中
或前面加Private
Public Sub Form_Load() 也错了
应该是
Private Sub Form_Load()
或前面加Private
Public Sub Form_Load() 也错了
应该是
Private Sub Form_Load()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Type studtype
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
定义到模块里去啊。form里不支持啊
no As Integer
name As String * 20
mark(1 To 3) As Single
total As Single
aver As Single
max As Single
min As Single
mid As Single
End Type
定义到模块里去啊。form里不支持啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把第一段的所有内容写在一行里面,用:分隔,再试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询