I'm a bit rusty and am updating a VB.Net program I wrote in 2013 using VS2017. I needed to expand a My.Settings StringCollection array by one entry. It was User scope, and I could not figure out how to enlarge the existing array, despite hours of online research and testing.
I tried using the .Add method, but was told "not a member of String." I tried deleting "user.config."
Finally I tried this, which worked: 1) At design time, in Settings, I added the extra placeholder value to my StringCollection variable. 2) Change the scope from User to Application. 3) Run the program. 4) Change the scope back to User. I confirmed this worked by inspecting My.Settings at runtime. What I want to know is: Why did this work, and is there a more elegant way to have done this?
For index = 0 To 5 'Motor numbers
'Changing upper index limit from 4 to 5 throws an Exception
strCommand = "(0," & index.ToString & ")"
My.Settings.strMotor_Kp(index) = (Kpid(0, index))
strCommand = "(1," & index.ToString & ")"
My.Settings.strMotor_Ki(index) = (Kpid(1, index))
strCommand = "(2," & index.ToString & ")"
My.Settings.strMotor_Kd(index) = (Kpid(2, index))
Next