如何读取ArrayList中的记录?

kinlin 2004-09-10 01:46:49
Dim hh As New ArrayList
Dim AndCond As New SqlAndCondition (自定义类型)
hh.Add(AndCond)
AndCond = hh.Item(0)
可是问题是无法读取,hh.Item(0)下面显示波浪线,还请高手赐教该如何读取?
...全文
759 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
水如烟 2004-09-10
  • 打赏
  • 举报
回复
Dim hh As New ArrayList
Dim AndCond As New SqlAndCondition (自定义类型)
hh.Add(AndCond)

Dim AndCond1 As SqlAndCondition
AndCond1=Ctype(hh.Item(0),SqlAndCondition)
.......
farrio 2004-09-10
  • 打赏
  • 举报
回复
当然读取不出来了,因为arraylist里面存的都是object型的。
如果你用的是简单的数据类型,就可以直接用。如果你存的是类的实例,
首先要Ctype啊。或者直接强制类型转换也可以。
我一般都这样用。
Dim AndCond As SqlAndCondition
For Each AndCond In ArrList
...
Next
这样就隐含着类型转换了。
或者直接 AndCond = ArrList(i) 也可以阿。
jiaming_wuming 2004-09-10
  • 打赏
  • 举报
回复
Dim obUpdate As New ArrayList
Dim strName As String
Dim a(2) As String
Dim i As Integer
Dim j As Integer
Dim strRet As String

strName = ""
strName = strName & "姓名" & "|"
strName = strName & "性别" & "|"
strName = strName & "年龄"

obUpdate.Add(strName.Trim)

strName = ""
strName = strName & "a" & "|"
strName = strName & "b" & "|"
strName = strName & "c"
obUpdate.Add(strName.Trim)

strName = ""
strName = strName & "e" & "|"
strName = strName & "f" & "|"
strName = strName & "g"

obUpdate.Add(strName.Trim)

For j = 0 To 2
For i = 0 To 2
strRet = obUpdate.Item(j)
a = strRet.Split("|")
MessageBox.Show(a(i))
Next
Next
冰峰zoubf 2004-09-10
  • 打赏
  • 举报
回复

Dim sortArrayList As New ArrayList
Dim AlCollect As ArrayListCollection

赋值
sortArrayList.Add(New ArrayListCollection(1, 1, 1, 1)
sortArrayList.Add(New ArrayListCollection(1, 1, 1, 1)
sortArrayList.Add(New ArrayListCollection(1, 1, 1, 1)

取值
For Each AlCollect In sortArrayList
Console.WriteLine(AlCollect.index)
Console.WriteLine(AlCollect.oriData)
Console.WriteLine(AlCollect.repData)
Console.WriteLine(AlCollect.sortData)
Next

'自定义类型,你可以改为别的
Public Class ArrayListCollection
Public index As Int16
Public oriData As Decimal
Public repData As Decimal
Public sortData As Decimal
Public Sub New(ByVal Inx As Int16, ByVal Dec_ori As Decimal, _
ByVal Dec_rep As Decimal, ByVal Dec_sort As Decimal)
index = Inx
oriData = Dec_ori
repData = Dec_rep
sortData = Dec_sort
End Sub
End Class
kinlin 2004-09-10
  • 打赏
  • 举报
回复
楼上的还是不行啊“性别”,“年龄”)有波浪线
cyy1981 2004-09-10
  • 打赏
  • 举报
回复
hh.Add(姓名",“性别”,“年龄”)
访问hh(0)
kinlin 2004-09-10
  • 打赏
  • 举报
回复
那如果向ArrayList中保存2维表的形式能实现吗?如:
姓名 性别 年龄
a b c
d e f
NULLvalue 2004-09-10
  • 打赏
  • 举报
回复
sqlandcondition从哪继承?
有没有重写sub new()
kinlin 2004-09-10
  • 打赏
  • 举报
回复
各位还是不行,如果换成
Dim hh As New ArrayList
Dim AndCond As New SqlAndCondition (自定义类型)
dim aa as new object
hh.Add(AndCond)
aa= hh.Item(0)
就能通过了,但还是无法从aa中取得数据,还请各位帮忙
llthero 2004-09-10
  • 打赏
  • 举报
回复
这样可以,挺简单
wnlovezxm 2004-09-10
  • 打赏
  • 举报
回复
hh[0],这是c#的用法,vb里就是用()的,
你这样写
Dim hh As New ArrayList
Dim AndCond As New SqlAndCondition (自定义类型)
hh.Add(AndCond)
AndCond = hh(0)
liutian32 2004-09-10
  • 打赏
  • 举报
回复
从你的代码看没有任何问题
llthero 2004-09-10
  • 打赏
  • 举报
回复
Dim myAL As New ArrayList
myAL.Add("The")
myAL.Add("quick")
myAL.Add("brown")
myAL.Add("fox")
Dim i As Integer
For i = 0 To 2
ComboBox1.Text = myAL.Item(i)
Next
NULLvalue 2004-09-10
  • 打赏
  • 举报
回复
Dim di As New ArrayList
di.Add("dog")
di.Item(0) = "Cat"
MsgBox(di.Item(0)) '运行正常
aycn 2004-09-10
  • 打赏
  • 举报
回复
我试了一下 kinlin (小林) 的代码并无问题,
问题是那个自定义类型是怎样定义的。
jiezhi 2004-09-10
  • 打赏
  • 举报
回复
hh[0]
gesnpt 2004-09-10
  • 打赏
  • 举报
回复
虽然不会vb但是ArrayList应该和数组的用法差不多

16,718

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧