Results 1 to 3 of 3

Thread: [RESOLVED] Question about being unable to store a string in a string array variable

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    Resolved [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?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Location
    Overland Park Kansas
    Posts
    183

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width