我刚学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

解决方案 »

  1.   

    Option ExplicitPrivate Type studType
            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
      

  2.   

    楼主代码的错误原因是 student定义成了过程级变量(定义到Form_Load过程里),而在其他过程里又用到它
    解决方法: 把它定义为模块级变量即可(定义到通用块里)