Page 1 of 1 1
Topic Options
#166988 - 2006-09-06 02:52 PM ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
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
#166989 - 2006-09-06 03:08 PM Re: ascan() doesn't work at all for multidimensional arrays
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm good one, have to wonder what kind of value ascan would return if it did work though.
Top
#166990 - 2006-09-06 03:18 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
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
#166991 - 2006-09-06 03:21 PM Re: ascan() doesn't work at all for multidimensional arrays
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
The dimension of the first hit?
Scanning Else would return "0,1"
Scanning Some would return "0,0"
Does that make sense?

Top
#166992 - 2006-09-06 03:24 PM Re: ascan() doesn't work at all for multidimensional arrays
Richard H. Administrator Offline
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
#166993 - 2006-09-06 03:28 PM Re: ascan() doesn't work at all for multidimensional arrays
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I dont know, just brain-storming here - what if ascan(multidim) returned an array of "dimensions" - that could be plugged back into the source array, maybe ...

$result = ascan($array,"Kixtart")

$array[$result[0],$result[1]] = "Kixtart Rocks"

Top
#166994 - 2006-09-06 03:29 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
richie, yup, that could work.
then need to ask jens to change his db codes to return arrays of arrays.
also, not sure how to do ascan with such an array either.
don't you need to do a wrapper for that also???
or are you scanning for arrays in the array?

Top
#166995 - 2006-09-06 03:30 PM Re: ascan() doesn't work at all for multidimensional arrays
Shawn Administrator Offline
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 Offline
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
#166997 - 2006-09-06 03:54 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shawn, don't think that would work.
ruud didn't code the multidim array and afaik, it doesn't support passing variables inside the []
not sure, but iirc it had some limitation like that.

Top
#166998 - 2006-09-06 04:04 PM Re: ascan() doesn't work at all for multidimensional arrays
Richard H. Administrator Offline
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
#166999 - 2006-09-06 04:13 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
multidim arrays should support either arrays or strings inside their brackets.
currently only way to do a proper wrapper requires executionist (tm jochen)

Top
#167000 - 2006-09-09 06:20 AM Re: ascan() doesn't work at all for multidimensional arrays
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See IsInArray() - Checks if a string is part of a array of strings , which supports multidimensional arrays.

The DB functions return a 2-D array, a.k.a. a table, under normal circumstances. Why would you need n-D returns unless you're working with some kind of cube-query?
_________________________
There are two types of vessels, submarines and targets.

Top
#167001 - 2006-09-16 10:08 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
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
#167002 - 2006-09-16 10:12 PM Re: ascan() doesn't work at all for multidimensional arrays
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'd say you'd go left-to-right. first dimension is the left-most, last dimension is the right-most
_________________________
There are two types of vessels, submarines and targets.

Top
#167003 - 2006-09-16 10:14 PM Re: ascan() doesn't work at all for multidimensional arrays
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that sounds right to me too...

also, think ubound should be enhanced to return the number of dims of multidim array.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1636 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.072 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org