#166988 - 2006-09-06 02:52 PM
ascan() doesn't work at all for multidimensional arrays
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
I didn't find anything real info on the board for this, so decided to raise the question again. should ascan work at all for multidim arrays? if not, manual should say so. (no, I didn't check the manual myself, just read in the forums that manual does not say a word about this) Code:
dim $a[1,1] $a[0,0] = "something" $a[0,1] = "else" $a[1,0] = "some" $a[1,1] = "else thing"
ascan($a,"else") ? ascan($a,"some") ?
get $
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#166990 - 2006-09-06 03:18 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
did a simple wrapper so could get my job done, but still wonder. isn't there anyone else experiencing the pain?
Code:
function MultiDimAscan($array,$scanfor) dim $ $MultiDimAscan = -1 for $=0 to ubound($array,1) if $scanfor = $array[$,0] $MultiDimAscan = $ endif next endfunction
and I wouldn't have to consider this at all, but doing 1400 queries against msSql server with kixtart always crashed after 1300+
|
|
Top
|
|
|
|
#166992 - 2006-09-06 03:24 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
It's only simple if the array has two dimensions. What about Array[10,10,10,10,10,10,10]?
In terms of return values, I think it would have to be a string reference e.g. "1,2,3".
I'm not sure how usefull that'd be though.
Whenever I need to use ASCAN with a 2D array I always create it in the Array[x][y] format.
|
|
Top
|
|
|
|
#166995 - 2006-09-06 03:30 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
hmmm, on further thought ...
Code:
$result = ascan($array,"Kixtart")
If UBound($result)
$array[$result[0],$result[1]] = "Kixtart Rocks"
Endif
|
|
Top
|
|
|
|
#166996 - 2006-09-06 03:41 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
don't you need to do a wrapper for that also???
Not if you know what the key index is. Here is a trivial example: Code:
Dim $aArray[2] $aArray[0]=Split("Apple Pear Orange") $aArray[1]=Split("10 20 30") "Number of Pears="+$aArray[1][AScan($aArray[0],"Pear")]+@CRLF
If you wanted to search every cell then yes, you'd need a wrapper.
|
|
Top
|
|
|
|
#166998 - 2006-09-06 04:04 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This set me thinking about writing a replacement ascan, and a function to convert aa[bb,cc,dd] format arrays to aa[bb][cc][dd] format.
One of the problems is working out the size of the array. This UDF does the job quite well, but it won't get arrays with undefined dimension. It returns an array where each element is the size of the corresponding dimension in the input array: Code:
Dim $a[10,20,1,2,3] $aResult=udfArraySize($a) "Array has "+(1+UBound($aResult))+" dimensions which are: $$a["+Join($aResult,",")+"]"? Exit 0 Function udfArraySize($a) Dim $iMaxArray $iMaxArray=20 Dim $i For $i=1 To $iMaxArray If UBound($a,$i)>0 Redim Preserve $udfArraySize[$i-1] $udfArraySize[$i-1]=UBound($a,$i) EndIf Next EndFunction
|
|
Top
|
|
|
|
#167001 - 2006-09-16 10:08 PM
Re: ascan() doesn't work at all for multidimensional arrays
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
getting back to this...
indeed, the scanner would need to know, where to look, so it would need to get the number of dimension to search in and the fields to look at. so to look into 5,5 of second and third dim of $array[4,5,6] one would need to call it something like: mAscan($array,"search","5,5",1)
btw, is first dimension the leftmost or the rightmost?
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|