Tip

User defined array class - Part II

Example of Array manipulation using a user defined array class. The code below is written on a button click event. Include the line below in the options event:

	Use "CLASS : Array"
	
	Sub Click(Source As Button)
	Dim Array As ArrayClass	
	Dim index As Integer
	
	Dim MyArray As Variant			
	Dim tmpArray( 2 )  As Variant
	tmpArray( 0 ) = "6"
	tmpArray( 1 ) = "7"
	tmpArray( 2 ) = "8"
	
	'-- Instantiate the Arrray object
	Set Array = New ArrayClass	
	MyArray = Array.Intialize( "0,1,2")

	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	%END REM
	
	MyArray =  Array.Add( "3,4,5" )
	
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "4"
	MyArray(5) = "5"
	%END REM

	MyArray =  Array.Add( " " )

	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "4"
	MyArray(5) = "5"
	MyArray(6) = " "
	%END REM

	MyArray = Array.AppendArray( tmpArray )
	
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "4"
	MyArray(5) = "5"
	MyArray(6) = " "
	MyArray(7) = "6"
	MyArray(8) = "7"
	MyArray(9) = "8"
	%END REM

	MyArray = Array.RemoveIndex( 4 )
	
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = " "
	MyArray(6) = "6"
	MyArray(7) = "7"
	MyArray(8) = "8"
	%END REM

	MyArray = Array.RemoveIndex( 6 )
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = " "	
	MyArray(6) = "7"
	MyArray(7) = "8"
	%END REM

	MyArray = Array.Replace( " ", "" )

	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = ""	
	MyArray(6) = "7"
	MyArray(7) = "8"
	%END REM

	MyArray = Array.TrimNull
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = "7"
	MyArray(6) = "8"
	%END REM

	MyArray =  Array.Add( " ,6   , 7   ,  8  " )
	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = "7"
	MyArray(6) = "8"
	MyArray(7) = " "
	MyArray(8) = "6   "
	MyArray(9) = " 7   "
	MyArray(10) = "  8  "
	%END REM

	MyArray =  Array.TrimAll

	%REM
	Reuslt
	MyArray(0) = "0"
	MyArray(1) = "1"
	MyArray(2) = "2"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = "7"
	MyArray(6) = "8"	
	MyArray(7) = "6"
	MyArray(8) = "7"
	MyArray(9) = "8"
	%END REM

	MyArray = Array.Replace( "0,1,2", "00,01,02" )
	%REM
	Reuslt
	MyArray(0) = "00"
	MyArray(1) = "01"
	MyArray(2) = "02"
	MyArray(3) = "3"
	MyArray(4) = "5"
	MyArray(5) = "7"
	MyArray(6) = "8"	
	MyArray(7) = "6"
	MyArray(8) = "7"
	MyArray(9) = "8"
	%END REM


	Index = Array.GetIndex( "01", 1 )

	%REM
	Reuslt
	Index = 1
	%END REM

	Index = Array.GetIndex( "001", 1 )
	%REM
	Reuslt
	If there is no match then -1 is returned
	Index = -1
	%END REM

	UB = Array.GetUpperBound
	%REM
	Reuslt
	If there is no match then -1 is returned
	UB = 9
	%END REM
	LB = Array.GetLowerBound
	%REM
	Reuslt
	If there is no match then -1 is returned
	LB = 0
	%END REM

	MyArray = Array.InsertValue ( "000", 0  )
	%REM
	Reuslt
	MyArray(0) = "000"
	MyArray(1) = "00"
	MyArray(2) = "01"
	MyArray(3) = "02"
	MyArray(4) = "3"
	MyArray(5) = "5"
	MyArray(6) = "7"
	MyArray(7) = "8"	
	MyArray(8) = "6"
	MyArray(9) = "7"
	MyArray(10) = "8"
	%END REM
	
	MyArray = Array.InsertValue ( "001", 1 )
	%REM
	Reuslt
	MyArray(0) = "000"
	MyArray(1) = "001"
	MyArray(2) = "00"
	MyArray(3) = "01"
	MyArray(4) = "02"
	MyArray(5) = "3"
	MyArray(6) = "5"
	MyArray(7) = "7"
	MyArray(8) = "8"	
	MyArray(9) = "6"
	MyArray(10) = "7"
	MyArray(11) = "8"
	%END REM
	
	MyArray =  Array.Add( "00,3" )
	%REM
	Reuslt
	MyArray(0) = "000"
	MyArray(1) = "001"
	MyArray(2) = "00"
	MyArray(3) = "01"
	MyArray(4) = "02"
	MyArray(5) = "3"
	MyArray(6) = "5"
	MyArray(7) = "7"
	MyArray(8) = "8"	
	MyArray(9) = "6"
	MyArray(10) = "7"
	MyArray(11) = "8"
	MyArray(12) = "00"
	MyArray(13) = "3"
	%END REM
	MyArray = Array.Unique	
	%REM
	Reuslt
	MyArray(0) = "000"
	MyArray(1) = "001"
	MyArray(2) = "00"
	MyArray(3) = "01"
	MyArray(4) = "02"
	MyArray(5) = "3"
	MyArray(6) = "5"
	MyArray(7) = "7"
	MyArray(8) = "8"	
	MyArray(9) = "6"	
	%END REM

	MyArray = Array.Extract( 15)
	%REM
	Reuslt
	MyArray(0) = "000"
	MyArray(1) = "001"
	MyArray(2) = "00"
	MyArray(3) = "01"
	MyArray(4) = "02"
	MyArray(5) = "3"
	MyArray(6) = "5"
	MyArray(7) = "7"
	MyArray(8) = "8"	
	MyArray(9) = "6"	
	%END REM
	
	MyArray = Array.Extract( -2 )
	
	%REM
	Reuslt
	MyArray(0) = "8"	
	MyArray(1) = "6"	
	%END REM
	
	MyArray = Array.ReplaceIndex( 1, "001" )

	%REM
	Reuslt
	MyArray(0) = "001"	
	MyArray(1) = "6"	
	%END REM
	
	End Sub

See Part I here

This was first published in June 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.