[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5114
  • Last Modified:

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?


            GetSQLTraceConfig()
            BuildConfigFile(currentSQLServer)
            RunUpgradeAdvisor()
       
        Next

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?

Thanks-



0
ndegioia
Asked:
ndegioia
  • 2
  • 2
1 Solution
 
SStoryCommented:
Well, for starters, how is currentSQLSever defined for Main?  Globally? As a string?  If so, why pass it back into BuildConfigFile?

Anyhow...

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
      debug.writeline(servers(i))
next
0
 
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.

Thanks-
0
 
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.
0
 
SStoryCommented:
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now