Option Base 1
Dim studname() As String*4
Sub Form_Click()
ReDim studname(10)
Dim i%,temp as String*4
For i=1 to 10
temp$=InputBox$(“Enter Name:”)
studname(i)=temp$
Next i
End Sub
上述程序中数组只能够保存10个同学的姓名,如果现在还要再录入10个同学的姓名到该数组中去,不能将原有的10个同学的数据删除,该怎么办?请在Next i的后面再追加程序。
如果在录入之前知道所有同学的个数,这样可以定义个固定的数组,比如我要录入30个那么就定义为:Dim studname(30) As String*4这里可以定义更大一点,以防止后来变化Dim studname(100) As String*4,用不到的就放在那里好了,录入的时候For i=1 to 100 temp$=InputBox$(“Enter Name:”) if trim(temp$)="" thenif msgbox("输入为空,是否结束录入?",vbokcancel)=vbok then exit forelse studname(i)=temp$ end ifNext i