How do I clear an array?

  • 13 years ago

    I was told by my instructor that instead of clearing all of the items in the array, there is a way to clear the enture array by doing something and I don't remeber what it was.  Below is my code for my array:

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

    sublistofvalues = sublistofvalues + 1

    listofvalues(sublistofvalues) = listboxTickerSymbols.SelectedItem

    listofvalues2(sublistofvalues) = Val(txtStockPrice.Text)

    listofvalues3(sublistofvalues) = Val(txtStockQuantity.Text)

    listofvalues4(sublistofvalues) = Val(txtStockPrice.Text * txtStockQuantity.Text)

    Dim stepthruarray As Long

    lblTickerSymbol.Text = ""

    lblStockPrice.Text = ""

    lblStockQuantity.Text = ""

    lblTotalValue.Text = ""

    For stepthruarray = 1 To sublistofvalues Step 1

    lblTickerSymbol.Text &= listofvalues(stepthruarray) & vbCrLf

    lblStockPrice.Text &= listofvalues2(stepthruarray) & vbCrLf

    lblStockQuantity.Text &= listofvalues3(stepthruarray) & vbCrLf

    lblTotalValue.Text &= listofvalues4(stepthruarray) & vbCrLf





  • 13 years ago

    I think you are probably looking for ReDim

    You can use this to change the extent of an array.

    If you include the optional keyword    Preserve     then the current contents are retained.

    If not, the array will be cleared for you.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“An idiot with a computer is a faster, better idiot” - Rich Julius