laoxie_198 发表于 2007-4-26 15:46:00

[求助]请问在vba里listbox控件怎么总是有问题?

<p>下面这段代码我在vb6.0里运行没问题怎么到vba里就不行了呢?总是提示:“无法获取list属性、属性阵列索引无效</p><p>Private Sub UserForm_Layout()<br/>Dim sjk As New ADODB.Connection<br/>Dim sjklj As String<br/>Dim dwzd As New ADODB.Recordset<br/>Dim dwjs As Double<br/>Dim zd() As String<br/>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj<br/>dwzd.Open "select aa=count(dwid) from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>If Not dwzd.EOF Then<br/>&nbsp; dwjs = dwzd.Fields("aa")<br/>End If<br/>dwzd.Close<br/>dwzd.Open "select * from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>ReDim zd(dwjs) As String<br/>i = 0<br/>Do While Not dwzd.EOF<br/>&nbsp; i = i + 1<br/>&nbsp; zd(i) = dwzd.Fields("dwname")<br/>&nbsp; dwzd.MoveNext<br/>Loop<br/>For j = 0 To i<br/>&nbsp; ListBox1.List(j) = zd(j + 1) '此处总是提示“无法获取list属性、属性阵列索引无效<br/>Next j</p><p>End Sub</p>

mccad 发表于 2007-5-1 14:49:00

去到最后一位循环时,J+1已经大于I了,肯定会无效。

兰州人 发表于 2007-10-23 12:49:00

本帖最后由 作者 于 2007-10-23 12:58:06 编辑 <br /><br /> <strong><p><strong>程序报错</strong></p></strong><p><strong>实时错误未发现数据源名称并且未指定默认驱动程序</strong></p><p>程序出错的位置</p><p>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj------------------------------错在这里</p><p>连接库Data Source=hbcad?????????????????<br/></p><p></p><p></p><p>---------------------</p><p>Private Sub UserForm_Layout()<br/>Dim sjk As New ADODB.Connection<br/>Dim sjklj As String<br/>Dim dwzd As New ADODB.Recordset<br/>Dim dwjs As Double<br/>Dim zd() As String<br/>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj<br/>dwzd.Open "select aa=count(dwid) from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>If Not dwzd.EOF Then<br/>&nbsp; dwjs = dwzd.Fields("aa")<br/>End If<br/>dwzd.Close<br/>dwzd.Open "select * from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>ReDim zd(dwjs) As String<br/>i = 0<br/>Do While Not dwzd.EOF<br/>&nbsp; i = i + 1<br/>&nbsp; zd(i) = dwzd.Fields("dwname")<br/>&nbsp; dwzd.MoveNext<br/>Loop<br/>For j = 0 To i<br/>&nbsp; ListBox1.List(j) = zd(j + 1) '此处总是提示“无法获取list属性、属性阵列索引无效<br/>Next j</p><p>End Sub</p>

crazylsp 发表于 2013-3-7 10:43:01

二楼正解,我试过类似问题对的
页: [1]
查看完整版本: [求助]请问在vba里listbox控件怎么总是有问题?