[RESOLVED] Question about being unable to store a string in a string array variable
I'm currently writing the inner text of an XML node to a string variable like this:
Code:
public MCO as string
MCO = node.SelectSingleNode(xml_subsPlanNode).InnerText
This is working fine. Now I'm needing to write the inner text of an XML node to an array
Code:
Public MCO(20) as string
public MCOcount as integer = 0
MCO(MCOcount) = node.SelectSingleNode(xml_subsPlanNode).InnerText
'this line of code gives the error "Property 'Chars' is 'ReadOnly'"
MCOcount = MCOcount + 1
I've tried searching online and not found any answer that makes any sort of sense to me. What am I doing wrong here?
Why is making my variable into a string array preventing me from storing data in it?
Re: [RESOLVED] Question about being unable to store a string in a string array variab
I found out what was causing the problem when i switched the variable from a string to an array there were other places where i was just trying to say
Code:
if MCO = "active" then
end if
instead of
Code:
if MCO(0) = "active" then
end if
When I corrected those and rebuilt my solution it was able to compile correctly
Re: [RESOLVED] Question about being unable to store a string in a string array variab
This is off-topic but, instead of using an array, you probably ought to be using a List(Of String). Where an array is fixed size, an collection will grow and shrink as you add and remove items. Instead of having to create an array with 20 empty elements and tracking the index, just create a List(Of T) and call its Add method each time you want to add an item. You can access items by index in exactly the same way as you do with an array.