Thread: Array problem
View Single Post
  #1 (permalink)  
Old 11-03-09, 11:23
Kabuki_jo Kabuki_jo is offline
Registered User
 
Join Date: Oct 2003
Posts: 61
Red face Array problem

I have written a function in VBA (access) that should parse some XML and then return the information in a two column Array. Now it seems to be working but the array it is returning seems to be in a different format to what I am used to and since it is to be used as input for another function (which i have not written) it is not desired. The code reads like this (added ratepairs in there for now but that will be taken from somewhere else in the future) :

Public Function YCRatepairs2()

Dim ratepairs1 As String

ratepairs1 = "<Tenors><Tenor name=""1Y SW"" value=""1.25"" /><Tenor name=""2Y SW"" value=""1.25"" /><Tenor name=""3Y SW"" value=""1.25"" /><Tenor name=""4Y SW"" value=""1.25"" /></Tenors>"

Dim xmlDoc As MSXML2.DOMDocument60
Dim xmlNodeList As MSXML2.IXMLDOMNodeList
Dim xmlNode As MSXML2.IXMLDOMNode

Dim myArray() As Variant

Set xmlDoc = New DOMDocument60

If (xmlDoc.loadXML(ratepairs1)) Then

Set xmlNodeList = xmlDoc.selectNodes("//Tenors/Tenor")
ReDim myArray(xmlNodeList.Length) As Variant

Dim cnt As Integer
cnt = 0
For Each xmlNode In xmlNodeList
myArray(cnt) = Array(xmlNode.Attributes(0).nodeValue, xmlNode.Attributes(1).nodeValue)
cnt = cnt + 1

Next

End If

YCRatepairs2 = myArray


End Function


Now what is strange is that when i add another line (msgbox in this case) to the code to view some data in the array I suddenly have to do this differently. Normally I would do this like this:

MsgBox (myArray(0,0))

However this gives me an error message saying "subscript out of range". When I chang it to this: MsgBox (myArray(0)(0)) it does work.

I have no clue as to why this is the case and moreover I need the first notation to work. Any ideas would be more then welcome.
__________________
Nobody dies a virgin because life screws us all!

Last edited by Kabuki_jo; 11-03-09 at 11:24. Reason: forgot something
Reply With Quote