Click here to Skip to main content
12,556,077 members (58,438 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Hello !
I wanna declare a string array without specifying the size of string array in That is, as new element comes, the array should grow at run time.
How can i do that?
Thanx in advance
Posted 22-May-12 22:40pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use a List instead:
Dim myList As New List(Of String)()
If you need it as an array at any time (to pass it to a method for example):
Dim myArray As String() = myList.ToArray()
VJ Reddy 23-May-12 5:13am
Nice answer. 5!
KNK143 23-May-12 5:24am
Dim myList As New List(Of String)() is showing an error...Comma,')' , or a valid continuation expected...
OriginalGriff 23-May-12 5:31am
I just pasted the code in my answer into a VB page and it compiles cleanly - check your code and make sure it is identical. If you can't see a problem, then copy and paste the relevant section of your code with the error message here.
losmac 23-May-12 11:16am
Good answer, my 5!
005bharat 31-May-13 4:53am
Great work!
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

If you wont use Generics, you can do it directly:

Dim s() As String
ReDim Preserve s(UBound(s) + 1)
s(UBound(s)) = "new valor"
KNK143 12-Jun-12 5:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

Dim stringArray As String()
' define three strings
Dim value1 As String = "lions"
Dim value2 As String = "tigers"
Dim value3 As String = "bears"
' using the Split() command, dynamically create them as a three element array
stringArray = Split(value1 + "," + value2 + "," + value3)
' define a fourth string
Dim value4 As String = "Oh my!"
' dynamically add to the array
stringArray = Split(Join(stringArray, ",") + ","+ value4, ",";)
' or, you could ...

stringArray = Split("lions" + "," + "tigers" + "," + "bears", ",")
stringArray = Split(Join(stringArray, ",") + "," + "Oh my!", ",")
CHill60 17-Jun-13 17:18pm
It's great that you want to help but this question is a year old and already resolved
Naveen_143 5-Jul-13 4:49am
thanks for your reply.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Dim webQuery As QueryWebService.Service = New QueryWebService.Service

    Dim queryDetails As String()
    Dim i As Integer = 0
    queryDetails = webQuery.getStudentQuery()
    While i < queryDetails.Length
        txtQuery.Text = txtQuery.Text + " " + queryDetails.GetValue(i)
        i = i + 1
    End While

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 17 Jun 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100