Assign value and Clear of Non Fix Size Array

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
May i know how to assign value to a non fix size array? Current i have declared a public string array in module and i need to assign value to this array from other forms, and i need to clear it up for next time assignment purpose. I cannot assign a collection of value because it is unknown so i have to assign one follow by another and this requires incremental on the array index in order to bound the value properly. May i know how to do all these? Thank you.
 
Are you able to use a List(Of ) type? It will allow you to add item nearly (?) ad infinitum, and then delete them when/if you need to.

VB.NET:
Dim myValues as List(Of String)
 
myVaules.Add("Test String")
myValues.Add("Test String")
 
myValues.Delete(0) 'Not using then IDE right now, I think that works.

Will that suit your purpose?
 
May i know why i can't add the item into the list using the following code,
Employee_ID_List.Add(
"E00001"), error message is "Object reference not set to instance of object", thank you.
 
Employee_ID_List is null


From raven65:
VB.NET:
Dim myValues as List(Of String)
 
myValues.Add("Test String") 'this code will crash. myValues has been declared but not instantiated

correction:
VB.NET:
Dim myValues as [B][SIZE=4][COLOR=red]New[/COLOR][/SIZE][/B] List(Of String)

myValues.Add("Test String")



retkehing, without wishing to appear rude, you seem to be asking a lot of questions that would be answered by a good book for those starting programming. May I suggest you seek out such a book and have a read of it? It will give you a better grounding in the concepts of programming than we can here, simply because we dont have the free time to put into the forum that which the author puts into the 600 page book to cover the basic principles like these.
 
Back
Top