I am new to VB, and I am trying to add data to an array from a textbox and have the data display in a listbox on a different form.
Can any body give me some generic examples. Thank you in advance for your time.


Edited by Jeff_12

4 Years
Discussion Span
Last Post by Minimalist

What is the event you want to use to move the data? Keypress? Buttonclick? Why do you want to move data into an array before moving it into a listbox? What code do you have sofar?


I think that you are trying to add information from textbox to an array and display it to listbox in another form.
if this is the case, then
you need to define array in a Module so that it is visible to all forms.
Then you can add text from textbox to the array, say after clicking a button.
But you must also keep track of number of elements in the array. If it is not known in advance, you can keep increasing the number every time a new element is added.
So if num is variable that stores the number of elements of the array, you increment every time a new element is added to the array
num = num+1
Next time you add another element you must re-dimension the array
so that the length of array gets incremented.
When you open the other form you can read the elements of the array and add to listbox as array is defined globally


If you just use: ReDim TheArray(num) you would loose all the values entered previously. To keep these you need to use: ReDim Preserve TheArray(num) where num can be num+1.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.