KeyFC欢迎致辞,点击播放
资源、介绍、历史、Q群等新人必读
KeyFC 社区总索引
如果你找到这个笔记本,请把它邮寄给我们的回忆
KeyFC 漂流瓶传递活动 Since 2011
 

关于那个程序

[ 4638 查看 / 4 回复 ]

目前的问题:
http://www.sydn.net/linkpics/help.png
分享 转发
黑手党左右铭:“互相帮助”的真正意义就是“相互利用”

无定时开放蜗牛级 FTP
动画 - ftp://anime@free.2288.org ]
同人 - ftp://doujin@free.2288.org ]

ONLINE状况留意下面的图片……

ftp://free.2288.org/online.gif
TOP

回复:关于那个程序

(2)
for i=0 to recordCount
if dataarray(i,0)<>"" then
x=x+1  //这么写实际是求A列非空单元个数之和而不是查找单元格
End If
If x=ListBox1.ListIndex Then
y=i
End If
Next

这段程序改成如下试试:
for i=0 to recordCount
if dataarray(i,0)<>"" and ListBox1.ListIndex=i then y=i
Next i
2004年6月1日起此ID已停用,登录密码已随机设置。若仍发现此ID有活动请联系管理员检查网络安全。
TOP

回复:关于那个程序

怎么会不是查找单元格呢?因为x=ListBox1.ListIndex的次数只有一次,所以y也只会被赋值一次,y就是对应行……

用上面的方法更加不能求当前选择的对应行??(在选择A2,A7,A8,A10,A12的时候,Y值都是0)这个问题刚刚解决了:

While Not x = ListBox1.ListIndex
    If dataArray(i, 0) <> "" Then
        x = x + 1
    End If
    i = i + 1
Wend
y = i - 1

现在只剩下另一个问题……
黑手党左右铭:“互相帮助”的真正意义就是“相互利用”

无定时开放蜗牛级 FTP
动画 - ftp://anime@free.2288.org ]
同人 - ftp://doujin@free.2288.org ]

ONLINE状况留意下面的图片……

ftp://free.2288.org/online.gif
TOP

回复:关于那个程序

暂时的最终版本……(有很多缺陷)
Public conn
Dim dataArray()
Public recordCount, fieldCount As Integer

Public Sub UserForm_Initialize() '全局过程
Dim rs, cs, x, i
Set conn = CreateObject("ADODB.Connection") '创建 conn 对象
conn.Open "Driver={Microsoft Excel Driver (*.xls)};dbq=D:\KeyWord.xls" '连接 Excel 数据库
Set rs = conn.Execute("SELECT * FROM [Index$]") '选择 Excel 数据表

'Static counts
'Set cs = conn.Execute("SELECT COUNT(*) FROM [Index$]")
'counts = cs(0)

SheetsList.Clear '清除原来的列表内容

If Not rs.EOF Or Not rs.BOF Then
    rs.MoveFirst
End If

While Not rs.EOF 'SheetsList 列表输出循环
    x = rs(0)
    If x <> "" And Not IsNull(x) Then
      SheetsList.AddItem x
    End If
    rs.movenext
Wend
Set rs = Nothing '释放 rs 对象
End Sub

Public Function ReadData()
Dim rs, x
Dim row, col As Integer
Set rs = conn.Execute("SELECT COUNT(*) FROM [" & SheetsList.Text & "$]")
recordCount = rs(0)
Set rs = Nothing

Set rs = conn.Execute("SELECT * FROM [" & SheetsList.Text & "$]") '选择 Excel 数据表
If rs.EOF Then
    fieldCount = 0
Else
    fieldCount = rs.fields.Count
End If

ReDim dataArray(recordCount, fieldCount)

row = 0
While Not rs.EOF
  For col = 0 To rs.fields.Count - 1
  If IsNull(rs(col)) Then x = "" Else x = rs(col)
  dataArray(row, col) = x
  Next
  row = row + 1
  rs.movenext
Wend

End Function

Private Sub SheetsList_Change()
Dim rs, x, i
Set rs = conn.Execute("SELECT * FROM [" & SheetsList.Text & "$]") '选择 Excel 数据表

ListBox1.Clear '清除原来的列表内容

'If Not rs.EOF Or Not rs.BOF Then
'    rs.MoveFirst
'End If

While Not rs.EOF 'ListBox1 列表输出循环
    x = rs(0)
    If x <> "" And Not IsNull(x) Then
      ListBox1.AddItem x
    End If
    rs.movenext
Wend
Set rs = Nothing '释放 rs 对象
End Sub

Private Sub ListBox1_Click()
ListBox2.Clear '清除原来的列表内容
ReadData
Dim i, x, y As Integer
i = 0: x = -1
'If Not dataArray(0, 0) = "" And Not IsNull(dataArray(0, 0)) Then
While x <> ListBox1.ListIndex '寻找当前选择的对应行
    If dataArray(i, 0) <> "" Then
        x = x + 1
    End If
    i = i + 1
Wend
If i > 0 Then
    y = i - 1
End If

TextBox1.Text = y

If dataArray(y, 1) <> "" Then
    ListBox2.AddItem dataArray(y, 1)
End If

For i = y + 1 To recordCount
    If dataArray(i, 0) = "" And dataArray(i, 1) <> "" Then
        ListBox2.AddItem dataArray(i, 1)
    End If
    If dataArray(i, 0) <> "" Then
    i = recordCount
    End If
Next
'End If
End Sub

Private Sub ListBox2_Click()
ListBox3.Clear '清除原来的列表内容
ReadData
Dim i, x, y As Integer
i = 0: x = -1

While x <> ListBox2.ListIndex '寻找当前选择的对应行
    If dataArray(i, 1) <> "" Then
        x = x + 1
    End If
    i = i + 1
Wend
If i > 0 Then
    y = i - 1
End If

TextBox1.Text = y

If dataArray(y, 2) <> "" Then
    ListBox3.AddItem dataArray(y, 2)
End If

For i = y + 1 To recordCount
    If dataArray(i, 1) = "" And dataArray(i, 2) <> "" Then
        ListBox3.AddItem dataArray(i, 2)
    End If
    If dataArray(i, 1) <> "" Then
    i = recordCount
    End If
Next

End Sub

Private Sub ListBox3_Click()
ListBox4.Clear '清除原来的列表内容
ReadData
Dim i, x, y As Integer
i = 0: x = -1

While x <> ListBox3.ListIndex '寻找当前选择的对应行
    If dataArray(i, 2) <> "" Then
        x = x + 1
    End If
    i = i + 1
Wend
If i > 0 Then
    y = i - 1
End If

TextBox1.Text = y

If dataArray(y, 3) <> "" Then
    ListBox4.AddItem dataArray(y, 3)
End If

For i = y + 1 To recordCount
    If dataArray(i, 2) = "" And dataArray(i, 3) <> "" Then
        ListBox4.AddItem dataArray(i, 3)
    End If
    If dataArray(i, 2) <> "" Then
    i = recordCount
    End If
Next

End Sub
Private Sub CommandButton1_Click()
End
End Sub

Private Sub UserForm_Click()
End
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
conn.Close '关闭数据库连接
Set conn = Nothing '释放 conn 对象
End Sub
黑手党左右铭:“互相帮助”的真正意义就是“相互利用”

无定时开放蜗牛级 FTP
动画 - ftp://anime@free.2288.org ]
同人 - ftp://doujin@free.2288.org ]

ONLINE状况留意下面的图片……

ftp://free.2288.org/online.gif
TOP

回复:关于那个程序

改用While wend啊~~~
总之能通过就好~~
第一个问题没看懂什么意思……你不采用解决问题2的思路再试试?
2004年6月1日起此ID已停用,登录密码已随机设置。若仍发现此ID有活动请联系管理员检查网络安全。
TOP