我有一些XML值,我想將它分配給一個類,我想知道是否可以遍歷類的某些元素(而不是創建類中的數組)。VBA - 爲某個類的某些元素賦值
所以參照下面的XML片段,我想有類設置爲從XML傳遞值如下:
event.homeTeamName
event.awayTeamName
event.homeSpread1
event.homeSpread2
event.homeSpread3
event.homeSpread4
event.homeSpread5
event.totalPoints1
event.totalPoints2
event.totalPoints3
event.totalPoints4
event.totalPoints5
,而不是
event.homeTeamName
event.awayTeamName
event.homeSpread(1)
event.homeSpread(2)
event.homeSpread(3)
event.homeSpread(4)
event.homeSpread(5)
event.totalPoints(1)
event.totalPoints(2)
event.totalPoints(3)
event.totalPoints(4)
event.totalPoints(5)
是有一種方法來循環通過homeSpread1 - homeSpread5 and totalPoints1 - totalPoints5從XML分配值時類的元素?我知道屬性獲取和屬性讓功能在類模塊內,但據我所見,這將導致不需要的類涉及數組。另外就我所見,我需要爲每個數組創建一個Property Let/Get。
下面是XML片斷的例子:
<homeTeam type="Team1">
<name>Brisbane Roar</name>
<rotNum>2151</rotNum>
</homeTeam>
<awayTeam type="Team2">
<name>Adelaide United</name>
<rotNum>2152</rotNum>
</awayTeam>
<periods>
<period lineId="234921091">
<spreads>
<spread>
<awaySpread>0.25</awaySpread>
<awayPrice>2.01</awayPrice>
<homeSpread>-0.25</homeSpread>
<homePrice>1.909</homePrice>
</spread>
<spread altLineId="1893988627">
<awaySpread>0.75</awaySpread>
<awayPrice>1.549</awayPrice>
<homeSpread>-0.75</homeSpread>
<homePrice>2.59</homePrice>
</spread>
<spread altLineId="1893988629">
<awaySpread>0.5</awaySpread>
<awayPrice>1.751</awayPrice>
<homeSpread>-0.5</homeSpread>
<homePrice>2.21</homePrice>
</spread>
<spread altLineId="1893988631">
<awaySpread>0</awaySpread>
<awayPrice>2.47</awayPrice>
<homeSpread>0</homeSpread>
<homePrice>1.598</homePrice>
</spread>
<spread altLineId="1893988633">
<awaySpread>-0.25</awaySpread>
<awayPrice>2.91</awayPrice>
<homeSpread>0.25</homeSpread>
<homePrice>1.444</homePrice>
</spread>
</spreads>
<totals>
<total>
<points>2.75</points>
<overPrice>2.02</overPrice>
<underPrice>1.884</underPrice>
</total>
<total altLineId="1893988628">
<points>2.25</points>
<overPrice>1.571</overPrice>
<underPrice>2.49</underPrice>
</total>
<total altLineId="1893988630">
<points>2.5</points>
<overPrice>1.793</overPrice>
<underPrice>2.12</underPrice>
</total>
<total altLineId="1893988632">
<points>3</points>
<overPrice>2.36</overPrice>
<underPrice>1.632</underPrice>
</total>
<total altLineId="1893988634">
<points>3.25</points>
<overPrice>2.69</overPrice>
<underPrice>1.49</underPrice>
</total>
</totals>
</period>
</periods>
如果這就是你想要做的,那麼你可以做到這一點。目前尚不清楚究竟是什麼阻止了你? –
這是我的問題 - 我想知道如何遍歷類的某些元素,其中的元素不是特定的數組 – brebbles
這通常是爲什麼這種類型的任務會使用數組:這樣做會讓你的生活變得更加困難。在你的情況下,答案可能是使用'CallByName' –