How to declare a string?

Discussion in 'ASP .Net' started by Shapper, Oct 13, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    I am declaring a String Array as follows:

    Dim labeltext As String()
    Select Case culture
    Case "pt-PT"
    labeltext = {"A...", _
    "B...", _
    "C...", _
    "D..."}
    Case "en-GB"
    Case Else
    End Select

    However it's not working?

    What am I doing wrong?

    I know it would work if I would do as follows:
    Dim labeltext As String = {"A...", _
    "B...", _
    "C...", _
    "D..."}

    Thanks,
    Miguel
    Shapper, Oct 13, 2005
    #1
    1. Advertising

  2. You have to do something like:
    labeltext = New String() {"A...", _
    "B...", _
    "C...", _
    "D..."}

    Array declarations allow you to omit the "New String[]" part, but
    assignments do not.

    --
    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB.NET to C# Converter
    Instant VB: C# to VB.NET Converter
    Instant J#: VB.NET to J# Converter
    Clear VB: Cleans up outdated VB.NET code


    "Shapper" wrote:

    > Hello,
    >
    > I am declaring a String Array as follows:
    >
    > Dim labeltext As String()
    > Select Case culture
    > Case "pt-PT"
    > labeltext = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    > Case "en-GB"
    > Case Else
    > End Select
    >
    > However it's not working?
    >
    > What am I doing wrong?
    >
    > I know it would work if I would do as follows:
    > Dim labeltext As String = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    >
    > Thanks,
    > Miguel
    >
    >
    =?Utf-8?B?RGF2aWQgQW50b24=?=, Oct 13, 2005
    #2
    1. Advertising

  3. Shapper

    Karl Seguin Guest

    labletext = new String() {"..", ",,")

    you could also use an arraylist if you wanted to.

    dim labelTExt as new ArrayList()
    ....
    labelText.Add("..")
    labelText.Add("..")
    labelText.Add("..")

    and convert it to a string array

    dim arr as string() = ctype(arr.ToArray(gettype(string)), string())

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:OL%...
    > Hello,
    >
    > I am declaring a String Array as follows:
    >
    > Dim labeltext As String()
    > Select Case culture
    > Case "pt-PT"
    > labeltext = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    > Case "en-GB"
    > Case Else
    > End Select
    >
    > However it's not working?
    >
    > What am I doing wrong?
    >
    > I know it would work if I would do as follows:
    > Dim labeltext As String = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    >
    > Thanks,
    > Miguel
    >
    Karl Seguin, Oct 13, 2005
    #3
  4. I think the assignment shortcut has to be used in one statement. You could
    use this if they are separate:

    Dim labeltext(4) As String
    Select Case Culture
    Case "pt-PT"
    labeltext(0) = "A..."
    labeltext(1) = "B..."
    labeltext(2) = "C..."
    labeltext(3) = "D..."
    Case "en-GB"
    Case Else
    End Select

    Ken
    MVP [ASP.NET]

    "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
    news:OL%...
    > Hello,
    >
    > I am declaring a String Array as follows:
    >
    > Dim labeltext As String()
    > Select Case culture
    > Case "pt-PT"
    > labeltext = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    > Case "en-GB"
    > Case Else
    > End Select
    >
    > However it's not working?
    >
    > What am I doing wrong?
    >
    > I know it would work if I would do as follows:
    > Dim labeltext As String = {"A...", _
    > "B...", _
    > "C...", _
    > "D..."}
    >
    > Thanks,
    > Miguel
    >
    Ken Cox [Microsoft MVP], Oct 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kwaj
    Replies:
    2
    Views:
    713
  2. Derek Graham

    How do I declare subpackages?

    Derek Graham, Sep 15, 2004, in forum: VHDL
    Replies:
    7
    Views:
    626
    valentin tihomirov
    Sep 18, 2004
  3. khawar
    Replies:
    1
    Views:
    7,274
    GastonQ
    Jul 10, 2003
  4. Boris Zakharin

    Error: Must Declare Variable

    Boris Zakharin, Jul 21, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    588
    Boris Zakharin
    Jul 22, 2003
  5. Gary
    Replies:
    5
    Views:
    290
    arnuld
    May 7, 2008
Loading...

Share This Page