1

If I do Dim array As String() I seem to be able to resize that array and put anything in it on the fly. For example:

Dim PackUrls As String() PackUrls = Split(WebRequest("http://" + sPackBaseURI, sPackBaseURIUsername, sPackBaseURIPassword), ":") 

And I don't get an error and nothing weird is happening with the array.

I did this without thinking THEN i read that you have to specify the size of the array first! Why is this happening?

2 Answers 2

1

This is what is happening in your code

'Create an empty string array called PackUrls Dim PackUrls As String() 'Create a new string array from the Split function 'and assign it to the variable PackUrls, replacing the old value. PackUrls = Split(WebRequest("http://" + sPackBaseURI, _ sPackBaseURIUsername, sPackBaseURIPassword), ":") 

There is no copying from the result of Split to PackUrls. The original content (which is nothing by the way) is replaced with the new content from Split. Therefore there is no need to resize the array. You could easily rewrite your code like this and it would work:

Dim PackUrls As String() = Split(WebRequest("http://" + sPackBaseURI, _ sPackBaseURIUsername, sPackBaseURIPassword), ":") 
Sign up to request clarification or add additional context in comments.

Comments

1

When you assign and array to var you are replacing it with the new array, no matter the size. The var now is pointing to a new data of the same type, so no error is needed.

When you assing a array to an array var you are not copying the items individually, but the variable is poiting to the new array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.