Hatena::Groupvb6

VB6メモ

[VB] [個人メモ] [仕事メモ] [アイデア] [Rubyの魔神]
[VB6クラス]
 | 

2016-06-02

VBS動的配列を使ったArrayList

Option Explicit

dim a



set a = new ArrayList

dim t1:set t1 = new test:t1.msg="1"
a.add(t1)
dim t2:set t2 = new test:t2.msg="2"
a.add(t2)
dim t3:set t3 = new test:t3.msg="3"
a.add(t3)
msgbox(a.Count)

dim item

for each item in a.item
	item.say
next

a.clear
msgbox("clear")
for each item in a.item
	item.say
next

a.add(t1)
a.add(t2)
a.add(t3)
msgbox(a.Count)


for each item in a.item
	item.say
next


a.Items(1).msg="say"
a.Items(1).say

class test
	public msg
	public sub say
		msgbox(msg)
	end sub
end class



'動的配列版
class ArrayList

	private m_Item()
	private m_count

	public sub Add(x)
		ReDim Preserve m_item(m_count)
		If IsObject(x) Then
			set m_item(m_count) = x
		else
			m_item(m_count) = x
		end if
		m_count = m_count + 1
	end sub

	public function Count
		Count = m_count
	end function

	public function Clear
		m_count=0
		Erase m_item
	end function

	public function Item
		Item = m_Item
	end function

	public function Items(n)
		If IsObject(m_Item(n)) Then
			set Items = m_Item(n)
		else
			Items = m_Item(n)
		end if
	end function

end class


ゲスト



トラックバック - http://vb6.g.hatena.ne.jp/garyo/20160602
 |