8 个解决方案
#1
补充:模块文件中的代码为:
'定义学生自定义类型
Type StudentType
snumber As Long '学号
sname As String * 20 '姓名
ssex As String * 1 '性别
sage As Integer '年龄
End Type
'定义顺序表
Const maxsize = 100
Type seqlist
list(maxsize) As Variant
size As Integer
End Type
Sub listget(L As seqlist, i As Integer, x As Variant) '查找元素
If i > L.size - 1 Or i < 0 Then '考虑i位置的合法性
MsgBox "查找位置错误"
Else
x = L.list(i)
End If
End Sub
窗体中的语句为:
Dim mylist As seqlist, i As Integer, student() As StudentType, x As StudentType
With student(0)
.snumber = 2000001
.sname = "张三"
.ssex = "男"
.sage = 20
End With
With student(1)
.snumber = 2000002
.sname = "李四"
.ssex = "男"
.sage = 21
End With
Call listinsert(mylist, 0, student(0))
Call listinsert(mylist, 1, student(1))
执行到语句Call listinsert(mylist, 0, student(0))时出错了。出现以上提示。请赐教。谢谢 。
'定义学生自定义类型
Type StudentType
snumber As Long '学号
sname As String * 20 '姓名
ssex As String * 1 '性别
sage As Integer '年龄
End Type
'定义顺序表
Const maxsize = 100
Type seqlist
list(maxsize) As Variant
size As Integer
End Type
Sub listget(L As seqlist, i As Integer, x As Variant) '查找元素
If i > L.size - 1 Or i < 0 Then '考虑i位置的合法性
MsgBox "查找位置错误"
Else
x = L.list(i)
End If
End Sub
窗体中的语句为:
Dim mylist As seqlist, i As Integer, student() As StudentType, x As StudentType
With student(0)
.snumber = 2000001
.sname = "张三"
.ssex = "男"
.sage = 20
End With
With student(1)
.snumber = 2000002
.sname = "李四"
.ssex = "男"
.sage = 21
End With
Call listinsert(mylist, 0, student(0))
Call listinsert(mylist, 1, student(1))
执行到语句Call listinsert(mylist, 0, student(0))时出错了。出现以上提示。请赐教。谢谢 。
#2
不好意思,上面模块文件中还漏了一个过程:
Sub listinsert(L As seqlist, i As Integer, x As Variant) '插入元素
Dim j As Integer
If L.size = maxsize Then
MsgBox "表已满,不能插入"
ElseIf i > L.size Or i < 0 Then '考虑i位置的合法性, 0<=i<=l.size-1
MsgBox "插入位置错误"
Else
For j = L.size To i Step -1
L.list(j + 1) = L.list(j)
Next
L.list(i) = x
L.size = L.size + 1
End If
End Sub
Sub listinsert(L As seqlist, i As Integer, x As Variant) '插入元素
Dim j As Integer
If L.size = maxsize Then
MsgBox "表已满,不能插入"
ElseIf i > L.size Or i < 0 Then '考虑i位置的合法性, 0<=i<=l.size-1
MsgBox "插入位置错误"
Else
For j = L.size To i Step -1
L.list(j + 1) = L.list(j)
Next
L.list(i) = x
L.size = L.size + 1
End If
End Sub
#3
用object代替你的那个type传进去
然后在函数里面
dim s as student
s=obj
然后在函数里面
dim s as student
s=obj
#4
clear_zero(清晰),不好意思,我不是太明白你的方法。
#5
Variant不包含用户自定议数据类型,所以用x As Variant传入type定义的类型是不可以的
如果是类,可以用clear_zero(清晰) 的方法
如果是类,可以用clear_zero(清晰) 的方法
#6
Variant 变量能够存储所有系统定义类型的数据。不包括自定义数据类型。
解决办法很多,MS建议用类代替UDT。你这里直接定义为x As StudentType就行了。
解决办法很多,MS建议用类代替UDT。你这里直接定义为x As StudentType就行了。
#7
楼上真是难得一见啊 :)
#8
谢谢大家。
#1
补充:模块文件中的代码为:
'定义学生自定义类型
Type StudentType
snumber As Long '学号
sname As String * 20 '姓名
ssex As String * 1 '性别
sage As Integer '年龄
End Type
'定义顺序表
Const maxsize = 100
Type seqlist
list(maxsize) As Variant
size As Integer
End Type
Sub listget(L As seqlist, i As Integer, x As Variant) '查找元素
If i > L.size - 1 Or i < 0 Then '考虑i位置的合法性
MsgBox "查找位置错误"
Else
x = L.list(i)
End If
End Sub
窗体中的语句为:
Dim mylist As seqlist, i As Integer, student() As StudentType, x As StudentType
With student(0)
.snumber = 2000001
.sname = "张三"
.ssex = "男"
.sage = 20
End With
With student(1)
.snumber = 2000002
.sname = "李四"
.ssex = "男"
.sage = 21
End With
Call listinsert(mylist, 0, student(0))
Call listinsert(mylist, 1, student(1))
执行到语句Call listinsert(mylist, 0, student(0))时出错了。出现以上提示。请赐教。谢谢 。
'定义学生自定义类型
Type StudentType
snumber As Long '学号
sname As String * 20 '姓名
ssex As String * 1 '性别
sage As Integer '年龄
End Type
'定义顺序表
Const maxsize = 100
Type seqlist
list(maxsize) As Variant
size As Integer
End Type
Sub listget(L As seqlist, i As Integer, x As Variant) '查找元素
If i > L.size - 1 Or i < 0 Then '考虑i位置的合法性
MsgBox "查找位置错误"
Else
x = L.list(i)
End If
End Sub
窗体中的语句为:
Dim mylist As seqlist, i As Integer, student() As StudentType, x As StudentType
With student(0)
.snumber = 2000001
.sname = "张三"
.ssex = "男"
.sage = 20
End With
With student(1)
.snumber = 2000002
.sname = "李四"
.ssex = "男"
.sage = 21
End With
Call listinsert(mylist, 0, student(0))
Call listinsert(mylist, 1, student(1))
执行到语句Call listinsert(mylist, 0, student(0))时出错了。出现以上提示。请赐教。谢谢 。
#2
不好意思,上面模块文件中还漏了一个过程:
Sub listinsert(L As seqlist, i As Integer, x As Variant) '插入元素
Dim j As Integer
If L.size = maxsize Then
MsgBox "表已满,不能插入"
ElseIf i > L.size Or i < 0 Then '考虑i位置的合法性, 0<=i<=l.size-1
MsgBox "插入位置错误"
Else
For j = L.size To i Step -1
L.list(j + 1) = L.list(j)
Next
L.list(i) = x
L.size = L.size + 1
End If
End Sub
Sub listinsert(L As seqlist, i As Integer, x As Variant) '插入元素
Dim j As Integer
If L.size = maxsize Then
MsgBox "表已满,不能插入"
ElseIf i > L.size Or i < 0 Then '考虑i位置的合法性, 0<=i<=l.size-1
MsgBox "插入位置错误"
Else
For j = L.size To i Step -1
L.list(j + 1) = L.list(j)
Next
L.list(i) = x
L.size = L.size + 1
End If
End Sub
#3
用object代替你的那个type传进去
然后在函数里面
dim s as student
s=obj
然后在函数里面
dim s as student
s=obj
#4
clear_zero(清晰),不好意思,我不是太明白你的方法。
#5
Variant不包含用户自定议数据类型,所以用x As Variant传入type定义的类型是不可以的
如果是类,可以用clear_zero(清晰) 的方法
如果是类,可以用clear_zero(清晰) 的方法
#6
Variant 变量能够存储所有系统定义类型的数据。不包括自定义数据类型。
解决办法很多,MS建议用类代替UDT。你这里直接定义为x As StudentType就行了。
解决办法很多,MS建议用类代替UDT。你这里直接定义为x As StudentType就行了。
#7
楼上真是难得一见啊 :)
#8
谢谢大家。