How to declare a string?

S

Shapper

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
 
G

Guest

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
 
K

Karl Seguin

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
 
K

Ken Cox [Microsoft MVP]

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]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top