Value of type 'String' cannot be converted to '1-dimensional array of String'

Ok, I understand that this is telling me I cannot pass an array into a string.  So here is where I am confused.

  Public Sub Main()

        Dim asr As AppSettingsReader = New AppSettingsReader
        Dim ServerList As String = CType(asr.GetValue("ServerList", GetType(String)), String)
        Dim Servers As String() = ServerList.Split(";")
       For Each server As String In Servers
       currentSQLServer = CStr(server) ' convert to string here, which means output is a string, right?


So why when I run a:

BuildConfigFile(ByVal currentSQLServer as string) ' Fires once per string element found

Dim split_String as string = currentSQLServer.split(“\”,1)
Dim split_string2 as string = currentSQLServer.split(“\”,2)

I get a conversion error?

They are both strings right, I cannot seem to isolate that string from the array eventhough only one string value is returned.

Any ideas?


Who is Participating?
SStoryConnect With a Mentor Commented:
Well, for starters, how is currentSQLSever defined for Main?  Globally? As a string?  If so, why pass it back into BuildConfigFile?


The problem I see is that you get a string() array from split and *NOT* a string.
Therefore if you want the first element you need to do

dim split_String as string=currentSQLServer.split("\")(0)

then (1)
then (2)

However it would be better to just say

dim Servers() as string=currentSQLServer.split("\")(0)

'this from memory....syntax could be a little wrong
for i a integer=0 to servers.getlengh()-1
      'write them out or whatever
ndegioiaAuthor Commented:
It originally did not need to be passed into the sub, I changed it in the hopes it was a scope issue.  This does make sense..I will give it a try.

ndegioiaAuthor Commented:
That worked as expected..It is always something easy like that when I get stuck.  I figured you had to identify the index of the array some how, I just did not know how to do it.

Thanks again.
Hey, wev've all been there.  That's why newsgroup and this group are such valuable resources to all of us.

Glad to be of help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.