Student Mode Code Display

Welcome to the Fraternity!

Commenting has been enabled. You can comment on all the Code Items now.

Remove Item from Array Using Dot Net Factory


Add This Code to My Favourite List
Enter Email

Contributed By admin
Date 2014-09-21 11:08:26

'REMOVING ELEMETNS FROM THE ARRAY

'Conventional VB Script Array is not cabable enough
'to perform some crucial array operations like Sorting,
'Deleting any item, Inserting Items in Between etc 
'This code Item displays example for 
' Deleting Element from the Dot net ArrayList.
' For Other Operation like Insert and Sort,
'Click on Dot Net Factory Tag under Tags Section

'Using Dot Net Factory above mentioned operations could be done
'quite easily.

'For Removing any item from the List

' There are Three methods for this in Dot Net Factory Array,
' depending on the requirement.

'a. Remove ' Mention the Element to be deleted
'b. RemoveAt" Mention the Index
'C. RemoveRange : Input argument for Range , Index and Length

'Note_1: Array List Index Starts from 0
' For Getting the Total Size of the Array: oDotNetFactArray.Count
'Note_2 Please Note that ArrayList is not a VB script Array but a
' Dot Net Factory Object.

'Note_3: ArrayList provides lots of good methods to manipulate arrays.
'These methods are cabaple of performing different actions on arrays,
'which are not possible using conventional vb script arrays or 
'Object Dictionary for that matter.

'Note_4: Examples mentioned Below contains same Object name.
' To check the code working Create seperate vbs file and Run each example
'individualy, else error will be generated.
'Enter comment or Give Feed back, if Code has some issue.

' EXAMPLE_1: EXAMPLE OF REMOVING ELEMENT USING VALUE

Dim oDotNetFactArray, Temp1
Set oDotNetFactArray = CreateObject("System.Collections.ArrayList")

oDotNetFactArray.Add("Akash")
oDotNetFactArray.Add("Tyagi")
oDotNetFactArray.Add("Prashant")
oDotNetFactArray.Add("Kumar")
oDotNetFactArray.Add("Padam")
oDotNetFactArray.Add("Gupta")

msgbox oDotNetFactArray.Count

' Removes the element containing "Tyagi"
oDotNetFactArray.Remove "Tyagi"


' Displays the current state of the ArrayList.
For Each Temp1 In oDotNetFactArray
    MsgBox Temp1
Next

'Output: Tyagi has been removed
'Akash
'Prashant
'Kumar
'Padam
'Gupta


'EXAMPLE_2: EXAMPLE OF REMOVING ELEMENT USING INDEX

Dim oDotNetFactArray, Temp1
Set oDotNetFactArray = CreateObject("System.Collections.ArrayList")

oDotNetFactArray.Add("Akash")
oDotNetFactArray.Add("Tyagi")
oDotNetFactArray.Add("Prashant")
oDotNetFactArray.Add("Kumar")
oDotNetFactArray.Add("Padam")
oDotNetFactArray.Add("Gupta")


' Removes the element at index 3.
oDotNetFactArray.RemoveAt(3)


' Displays the current state of the ArrayList.
For Each Temp1 In oDotNetFactArray
    MsgBox Temp1
Next

'Output: Kumar is at index 3
'Akash
'Tyagi
'Prashant
'Padam
'Gupta

'EXAMPLE_3: EXAMPLE OF REMOVING ELEMENT USING RANGE

Dim oDotNetFactArray, Temp1
Set oDotNetFactArray = CreateObject("System.Collections.ArrayList")

oDotNetFactArray.Add("Akash")
oDotNetFactArray.Add("Tyagi")
oDotNetFactArray.Add("Prashant")
oDotNetFactArray.Add("Kumar")
oDotNetFactArray.Add("Padam")
oDotNetFactArray.Add("Gupta")


' Removes three elements starting at index 2.
oDotNetFactArray.RemoveRange(2, 3)


' Displays the current state of the ArrayList.
For Each Temp1 In oDotNetFactArray
    MsgBox Temp1
Next

'Output: Item Removed from Prashant Till Padam
'Akash
'Tyagi
'Gupta

Download Above Code

Comments:



Add your comments...
Name : *      
Email : *      
The content of this field will be kept private and will not be shown publicly

Your Comment/Answer *

Enter the text present in this box : *