我刚学VB ,编了一段代码,可调不通,请大虾们指教,谢谢!
Private Type studType
stud_id As Integer
stud_name As String
stud_s As Integer
stud_address As String
End Type
Private Sub cmdArray_Click(Index As Integer)
Dim i As Integer
If Index = 0 Then
For i = 0 To 1
student(i).stu_id = InputBox("请输入第" & (i + 1) & "个学生的学号:")
student(i).stud_name = InputBox("请输入第" & (i + 1) & "个学生的姓名:")
student(i).s = InputBox("请输入第" & (i + 1) & "个学生的成绩:")
student(i).stud_address = InputBox("请输入第" & (i + 1) & "个学生的地址:")
Next i
For i = 0 To 1
Print student(i).stu_id
Print student(i).stud_name
Print student(i).s
Print student(i).stud_address
Next i
Else
If MsgBox("确实要退出吗?", vbQuestion + vbYesNo, "退出") = vbYes Then
Unload Me
End
End If
End SubPrivate Sub Form_Load()
Dim student(1) As studType
End Sub
Private Type studType
stud_id As Integer
stud_name As String
stud_s As Integer
stud_address As String
End Type
Private Sub cmdArray_Click(Index As Integer)
Dim i As Integer
If Index = 0 Then
For i = 0 To 1
student(i).stu_id = InputBox("请输入第" & (i + 1) & "个学生的学号:")
student(i).stud_name = InputBox("请输入第" & (i + 1) & "个学生的姓名:")
student(i).s = InputBox("请输入第" & (i + 1) & "个学生的成绩:")
student(i).stud_address = InputBox("请输入第" & (i + 1) & "个学生的地址:")
Next i
For i = 0 To 1
Print student(i).stu_id
Print student(i).stud_name
Print student(i).s
Print student(i).stud_address
Next i
Else
If MsgBox("确实要退出吗?", vbQuestion + vbYesNo, "退出") = vbYes Then
Unload Me
End
End If
End SubPrivate Sub Form_Load()
Dim student(1) As studType
End Sub
stud_id As Integer
stud_name As String
stud_s As Integer
stud_address As String
End Type
Dim student() As studType
Private Sub cmdArray_Click(Index As Integer)
Dim i As Integer
If Index = 0 Then
For i = 0 To 1
student(i).stud_id = CInt(InputBox("请输入第" & CStr(i + 1) & "个学生的学号:"))
student(i).stud_name = InputBox("请输入第" & CStr(i + 1) & "个学生的姓名:")
student(i).stud_s = CInt(InputBox("请输入第" & CStr(i + 1) & "个学生的成绩:"))
student(i).stud_address = InputBox("请输入第" & CStr(i + 1) & "个学生的地址:")
Next i
For i = 0 To 1
Print student(i).stud_id
Print student(i).stud_name
Print student(i).stud_s
Print student(i).stud_address
Next i
Else
If MsgBox("确实要退出吗?", vbQuestion + vbYesNo, "退出") = vbYes Then
Unload Me
End
End If
End If
End Sub
Private Sub Form_Load()
ReDim student(1)
End Sub
解决方法: 把它定义为模块级变量即可(定义到通用块里)