[2005] Continued from previous thread....array or arrayList
Continuing from a previous thread (http://www.vbforums.com/showthread.php?&t=429114) i came across a little problem. When copying the elements of the previous array into the new one i noticed that its copying all the elements that have nothing in them, so instead of adding, for example, one element across each time, its copying 2 and i have a load of elements in my new array that have nothing in them. So how can i change the code in posted in the previous thread so that only the element that contains something is copied?
1 Attachment(s)
Re: [2005] Continued from previous thread....array or arrayList
Huh? How is it copying two elements at a time? I think you need to give an example of what each array contains before the operation and then what the resized array contain afterwards, and show EXACTLY what code you're using. I used this code:
VB Code:
Dim existingArray As String() = {"String1", "String2", "String3"}
Dim arrayToAdd As String() = {"String4", "String5", "String6"}
Dim originalLength As Integer = existingArray.Length
Array.Resize(existingArray, originalLength + arrayToAdd.Length)
arrayToAdd.CopyTo(existingArray, originalLength)
MessageBox.Show(String.Join(", ", existingArray))
and it produced the result below, exactly as you'd expect.
Re: [2005] Continued from previous thread....array or arrayList
I think its because i am doing this all on a separate thread which is controlled by a timer, so everytime the timer ticks a new XML file is downloaded and the information is stored in arr_Results.
Here's the code i have anyway just for reference:
VB Code:
Private Sub tmr_Thread_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_Thread.Tick
threadTick = True
Dim thread1 As New Thread(New ThreadStart(AddressOf Me.getResults))
thread1.Start() ' start results thread
End Sub
Private Sub getResults()
copy_web_to_local(destination folder, "web_address_of_XML_file", "XML_file.xml")
getResultsXML(CACHE_DIRECTORY & "results.xml")
createTxtResults()
End Sub
Public Sub getResultsXML(ByVal _file As String)
'
Try
xml_doc = New XmlDocument() 'Create the XML Document
xml_doc.Load(_file) 'Load the Xml file
xml_nodelist = xml_doc.SelectNodes("/results/result") 'Get the list of name nodes
xml_length = xml_nodelist.Count() 'Length of xml_nodelist
'
i = 0
'
For Each xml_node In xml_nodelist 'Loop through the nodes
'
Dim att_time = xml_node.ChildNodes.Item(0).InnerText
Dim att_name = xml_node.ChildNodes.Item(1).InnerText
Dim att_method = xml_node.ChildNodes.Item(2).InnerText
'
arr_Results(i).time = att_time
arr_Results(i).name = att_name
arr_Results(i).method = att_method
ReDim Preserve arr_Results(i + 1)
i += 1
Next
originalLength = arr_storeResults.Length
Array.Resize(arr_storeResults, originalLength + arr_Results.Length)
arr_Results.CopyTo(arr_storeResults, originalLength)
Catch webEx As System.Net.WebException
MsgBox("Web Exception caught in FileFromWeb.copy_web_to_local()" & NL & "Reason: " & webEx.ToString())
Catch ex As Exception
MsgBox("Exception caught in FileFromWeb.copy_web_to_local()" & NL & "Reason: " & ex.ToString())
End Try
'
End Sub
and the when the timer has ticked twice the content of arr_storeResults are:
arr_storeResults(0) = nothing
arr_storeResults(1) = result
arr_storeResults(2) = nothing
arr_storeResults(3) = result
arr_storeResults(4) = nothing etc...