这是我进行练习的教师排课系统中的开设课程代码设置.但只能限定10门课,怎样才能扩大可输入的科目? 请高手指教一下!多谢了!(我已经试过把所有的9改为13,可是出错信息显示实时错误'340',控件数组元素'10'不存在.)
Option Explicit
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim str(13) As String
'Dim strSql As String
Private Sub cn_Click(Index As Integer)
'On Error GoTo ex:
Dim lcnt As Integer
Dim strTxt As String
Select Case Index
Case 0:
CanSave (True)
Case 1:
con.Execute ("delete * from subject")
For lcnt = 0 To 13
strTxt = Trim$(LTrim$(Txt(lcnt).Text))
If Len(strTxt) > 0 Then
rs.AddNew
rs!csjname = strTxt
rs.Update
End If
Next lcnt
CanSave (False)
Case 2:
For lcnt = 0 To 13
Txt(lcnt) = str(lcnt)
Next lcnt
CanSave (False)
End Select
Exit Sub
ex:
MsgBox "database error", vbOKOnly + vbExclamation, "error"
End Sub
Private Sub Form_Load()
'strSql = "insert into subject values( '"
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
Call clearTxt
CanSave (False)
con.Open "provider=Microsoft.Jet.OLEDB.4.0; data source= " & App.Path & "\dataUse.mdb"
rs.Open "select * from subject", con, adOpenStatic, adLockOptimistic
Call displayInfo
End Sub
Private Sub CanSave(bSave As Boolean)
Frame1.Enabled = bSave
cn(1).Enabled = bSave
cn(2).Enabled = bSave
cn(0).Enabled = Not bSave
End Sub
Private Sub displayInfo()
rs.MoveFirst
Dim lcnt As Integer
lcnt = 0
While (Not rs.EOF And lcnt < 14)
Txt(lcnt).Text = rs!csjname
str(lcnt) = Txt(lcnt).Text
lcnt = lcnt + 1
rs.MoveNext
Wend
End Sub
Private Sub clearTxt()
Dim lcnt As Integer
For lcnt = 0 To 13
Txt(lcnt).Text = ""
Next lcnt
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
End Sub