none
vb.net Clear Array

    Question

  •  

    Can any one help, I am trying to clear an array info(8), set all components to zero, nothing.

    Erase info causes failures with subsequent functions.

     

    I have searched books and msdn forums without success.

    The only reference I have found: [Call System.Array.Clear(info, info.GetLowerBound(0), info.Length)]

    Unfortunately this don’t work .

    Saturday, December 13, 2008 7:26 PM

Answers

  • What more do you want this:  

    Array.Clear(Info, Info.GetLowerBound(0), Info.Length)

    to do?

    It sets all elements of the array to Nothing.  There isn't much more that can be done unless you want to fill the array with some initializer.

    • Marked as answer by hemo Saturday, December 13, 2008 11:09 PM
    Saturday, December 13, 2008 7:44 PM

All replies

  • What more do you want this:  

    Array.Clear(Info, Info.GetLowerBound(0), Info.Length)

    to do?

    It sets all elements of the array to Nothing.  There isn't much more that can be done unless you want to fill the array with some initializer.

    • Marked as answer by hemo Saturday, December 13, 2008 11:09 PM
    Saturday, December 13, 2008 7:44 PM
  • I have tried,
    Array.Clear(Info, Info.GetLowerBound(0), Info.Length) which returns an error ' Index was outside the bounds of the array'

    hemo
    Saturday, December 13, 2008 9:37 PM
  • Why are you getting that error?  Put a breakpoint on that line to find out.  What are the bounds of the array?
    Saturday, December 13, 2008 9:56 PM
  •  Sorry made a stupid error. The code works fine. Thanks for your patience.
    Saturday, December 13, 2008 11:09 PM
  • Hi ALL,

    An array can only have a lower bound of zero so why not simply use.>>

    Dim info(0 To 20) As Integer

    Array.Clear(info, 0, info.Length)


    Regards,

    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    Sunday, December 14, 2008 7:46 AM
  •  

    That’s progress. Thanks

    hemo

    Sunday, December 14, 2008 3:02 PM
  • Hi,

    I've declared a array inside the structure and i want to clear that array from other function. Here is my program,

    Public class()
       
     Public Structure KBCContents
        Dim DEF_Array() As String 'Declare DEFinition Array
        Dim ValueTable As String 'Declare ValueTable
     End Structure

     Public Function process()
      Process step 1...
      Process step 2...
      Process step 3...
      Clear()
     End Function()

     Sub clear()
     
       Dim ClearStructureData As New KBCContents
      
       ClearStructureData.DEF_Array()="" ' This is not working; Need to know how to clear this array; also array size is not known. 
     
    End Sub

    End Class()

    Let me know, how to clear "DEF_Array()" array contents

    Thanks,
    -Baskar


    Measurment & Automation Platform
    Wednesday, January 21, 2009 4:35 PM
  • Baskar:

    You should start a new thread and post your initialization code for the structure.

    Wednesday, January 21, 2009 5:00 PM