| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 932 人关注过本帖, 1 人收藏
标题:在MSHFlexGrid1中新加一行,运行时老是提示下标越界(问题以解决)
只看楼主 加入收藏
cccool
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:268
专家分:555
注 册:2007-5-1
结帖率:100%
收藏(1)
 问题点数:0 回复次数:4 
在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编辑过]

搜索更多相关主题的帖子: 越界 运行 提示 tushubianhao 
2007-07-30 18:04
cccool
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:268
专家分:555
注 册:2007-5-1
收藏
得分:0 
怎么没人帮帮我啊!!!

[fly]让心情飞一会[/fly]
">Email to Me     
2007-07-30 18:52
hai99
Rank: 1
等 级:新手上路
帖 子:146
专家分:0
注 册:2007-7-2
收藏
得分:0 
没设置总列数cols
2007-07-30 18:55
cccool
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:268
专家分:555
注 册:2007-5-1
收藏
得分:0 

还是谢谢回帖
加了还是提示下标越界啊!!到底是什么地方出错了??


[fly]让心情飞一会[/fly]
">Email to Me     
2007-07-30 19:06
cccool
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:268
专家分:555
注 册:2007-5-1
收藏
得分:0 
找到答案了 .TextMatrix(tushubianhao , 0) = tushubianhao
.TextMatrix(tushubianhao , 1) = tushumingcheng
.TextMatrix(tushubianhao , 2) = zuozhexingming
.TextMatrix(tushubianhao , 3) = chubanshe
.TextMatrix(tushubianhao , 4) = chubanriqi
.TextMatrix(tushubianhao , 5) = tushudanjia
.TextMatrix(tushubianhao , 6) = tushuleibie
TextMatrix(i,j)中i,j都是从0开始的,但新问题又出来了,新加的数据在MSHFlexGrid1上显示的格式不一样,比如说出版日期,以前是显示6/3/2001,
现在我输入2001-3-6,他就显示2001-3-6,只有当再次进入程序时才显示6/3/2001,有没有什么办法使他及时显示相同的格式

[fly]让心情飞一会[/fly]
">Email to Me     
2007-07-30 19:29
快速回复:在MSHFlexGrid1中新加一行,运行时老是提示下标越界(问题以解决)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032435 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved