User defined array class - Part II

This user defined array class can be used for manipulating all kinds of operations on arrays.

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 last published in June 2002

Dig Deeper on Domino Resources - Part 5

Start the conversation

Send me notifications when other members comment.

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

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close