Exabytes beginner

Wednesday, June 27, 2007

Convert elements in multidimensional array to single dimensional array

function to_single_array(aelement,arr_col)
' convert multidimension array to single array
if isarray(aelement) then
for i=0 to ubound(aelement,2)
strval=strval & aelement(arr_col,i) & ","
next
strval=left(strval,len(strval)-1)
to_single_array=split(strval,",")
'response.write strval & "strval"
end if
end function

aelement is the name of multi dimensional array while arr_col is the column number which we want to converts into single array
this is the example of the multidimensional array

tr>


NameAge


Amy Jefferson

17




Mark Tan

25




John Grissam

29



Kathleen Rowling

35




so if the array name is ainfo, the way to extract the name into a single dimension array is
ainfo2=to_single_array(ainfo,0)

ainfo2 elements to will be:

Amy Jefferson
Mark Tan
John Grissam
Kathleen Rowling

any errors or feedback forward it to : nor@melur.com

Single Dimension Array concatenation

Single dimension array

Most of the time you will find that you need to concatenate 2 or more arrays.Somehow in classic asp there's no built in function that can combine array in one command. At least not that i know. Fill with the desperation to do it most of the time i wrote a simple function to concatenate 2 or more arrays

First i create a function call concat:

Function concat(array1,array2)
str1=join(array1,",")
str2=join(array2,",")
str3=str1 & "," &
str2 concat=split(str3,",")
end function

then I call the function anywhere when you need to concatenate arrays. For example, you want concatenate single dimension array

aitem1=array("A1","A1","A3")
aitem2=array("A4","A5","A6")

using this function:
aitem3=concat(aitem1,aitem2)

The elements for aitem3 are: "A1","A1","A3","A4","A5","A6"

I AM THE AUTHOR
Noraida Arifin
16 years  programming experience and  still learning.
spent 13 years of my life span as a software engineer
in a multinational company
Currently  a retire programmer.
Feedback are welcome.
Contact me at :
https://www.facebook.com/makcikprogrammer