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

Posted on 2006-05-04
Last Modified: 2007-12-19
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?


Question by:ndegioia
    LVL 25

    Accepted Solution

    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
    LVL 4

    Author Comment

    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.

    LVL 4

    Author Comment

    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.
    LVL 25

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now