在MSHFlexGrid1中新加一行,运行时老是提示下标越界(问题以解决)
我想在MSHFlexGrid1中新加一行,但是运行时老是提示下标越界,哪位高手看看什么怎么回事?代码如下:
Private Sub Command1_Click()
tushubianhao = Text1.Text
tushumingcheng = Text3.Text
zuozhexingming = Text5.Text
chubanshe = Text7.Text
chubanriqi = Text2.Text
tushudanjia = Text4.Text
tushuleibie = Text6.Text
If tushumingcheng = "" Then
MsgBox "请输入图书名称!", vbOKOnly
End If
If tushubianhao = "" Then
MsgBox "请输入图书编号!", vbOKOnly
End If
If zuozhexingming = "" Then
MsgBox "请输入作者姓名!", vbOKOnly
End If
If chubanshe = "" Then
MsgBox "请输入出版社!", vbOKOnly
End If
If chubanriqi = "" Then
MsgBox "请输入出版日期!", vbOKOnly
End If
If tushudanjia = "" Then
MsgBox "请输入图书单价!", vbOKOnly
End If
If tushuleibie = "" Then
MsgBox "请输入图书类别!", vbOKOnly
End If
Dim cn As New ADODB.Connection
Dim BookRec As New ADODB.Recordset
Dim BookSql As String
BookSql = "select * from 图书目录"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\jjz\桌面\陈良勇\图书馆\BOOK.MDB;Persist Security Info=False"
cn.Open
BookRec.Open BookSql, cn, adOpenKeyset, adLockOptimistic
With BookRec
.AddNew
.Fields("图书编号") = tushubianhao
.Fields("图书名称") = tushumingcheng
.Fields("作者姓名") = zuozhexingming
.Fields("出版社") = chubanshe
.Fields("出版日期") = chubanriqi
.Fields("图书单价") = tushudanjia
.Fields("图书类别") = tushuleibie
.Update
.Close
End With
With MSHFlexGrid1
.Rows = .Rows + 1
.TextMatrix(tushubianhao + 1, 0) = tushubianhao
.TextMatrix(tushubianhao + 1, 1) = tushumingcheng
.TextMatrix(tushubianhao + 1, 2) = zuozhexingming
.TextMatrix(tushubianhao + 1, 3) = chubanshe
.TextMatrix(tushubianhao + 1, 4) = chubanriqi
.TextMatrix(tushubianhao + 1, 5) = tushudanjia
.TextMatrix(tushubianhao + 1, 6) = tushuleibie
End With
MsgBox "图书目录增加成功!", vbOKOnly
Text1.Text = Text1.Text + 1
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
MSHFlexGrid1.Refresh
End Sub
[此贴子已经被作者于2007-7-30 20:06:17编辑过]