tags:

views:

67

answers:

5

im getting an exception on this:

Dim strings_extreme As String()
strings_extreme(0) = ""

it says that i am using it before it is being assigned a value

how do i initialize it?

please note that i need to be able to do this:

strings_extreme = input.Split(","c).Distinct().OrderBy(Function(s) s)
+2  A: 
Dim strings_extreme(10) As String
strings_extreme(0) = ""

Further info: http://www.startvbdotnet.com/language/arrays.aspx

Y. Shoham
this will not work because i dont know how big the array is
I__
Then you don't need an array but rather a list.
voyager
+3  A: 
Dim strings_extreme As List(Of String) = New List(Of String)
strings_extreme.Add("value1")
strings_extreme.Add("value 2")
strings_extreme.Add("value 3rd")
strings_extreme.Add("value again")

Dim strings() As String = strings_extreme.ToArray()

...
Gabriel McAdams
this will not work because i dont know how big the array is
I__
I would not use arrays then. Look into Generic List and ArrayList (arraylist ONLY if you do not know the type).
Gabriel McAdams
But with `ReDim` you can enlarge it when you need. Maybe you should try other kind of containers, like `List`.
Y. Shoham
you cannot use ReDim within an If-Then statement
I__
I modified the answer to use a List (Generics)
Gabriel McAdams
that doesnt work since i need to use this strings_extreme = input.Split(","c).Distinct().OrderBy(Function(s) s)
I__
List has a ToArray() method. Use that and you'll get a string array like you need
Gabriel McAdams
how? please show me
I__
Look at my modified answer
Gabriel McAdams
A: 

Shouldn't bother setting a string to "".

Try using:

Dim strings_extreme(10) As String
strings_extreme(yourIndex) = String.Empty
JonH
string is not a member of system.array
I__
Doesn't have to be what I meant was strings_extreme(yourIndex) = String.Empty
JonH
+2  A: 
Dim strings_extreme as String() = {"yourfirstitem"}

But actually, why not take a look at some more advanced data structure from System.Collections namespace?

naivists
+6  A: 

If you truly don't know how many strings there are going to be, then why not just use an IList:

Dim stringList As IList(Of String) = New List(Of String)
stringList.Add("")

You can get the Count of how many strings there are and you can For Each through all the strings in the list.

EDIT: If you're just trying to build an array from a Split you should be able to do this:

Dim strings_extreme() As String = input.Split(...)
CAbbott
nope i need it in two lines
I__