know an array

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

know an array

Post by Silvio.Falconi »

I have a dbf and save the records on a array with conditions saving only the number of invoice (n)

if I created an array type

AaDd(aSilvio, {n})

if I would like to know if a number (n) has been inserted into that array more than once, how should I know?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
darioflores
Posts: 16
Joined: Tue Oct 06, 2015 7:06 am

Re: know an array

Post by darioflores »

Hello, you could try something like this:

Code: Select all


   nIterations := 0
   
   nPos := aScan(aArray, {|x| x[1]==nFac})
   do while nPos>0
      nIterations++
      nPos := aScan(aArray, {|x| x[1]==nFac}, nPos+1)
   enddo

 
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: know an array

Post by Silvio.Falconi »

thanks
I wish search on rooms
the room number 13 have two bookings
I made

Code: Select all

Function ControlloMulti(aMultiplePre,nNumero,nStatus,cGuest ,cTypeDay)
   Local t
   Local lReturn :=.f.
   Local nTimes:= 0
   Local nIterations:=0
   Local   nPos := aScan(aMultiplePre, {|x| x[1]==nNumero})

   do while nPos>0
      nIterations++
      nPos := aScan(aMultiplePre, {|x| x[1]==nNumero}, nPos+1)
   enddo

   IF  nIterations >1
      AaDd(aPreMulti,{nNumero,nStatus,cGuest ,cTypeDay } )
     lReturn :=.t.
  endif

return  lReturn
 
the problem is I see only one booking and not all for a room sample on room 13 I have two bookings but the function show me this

Image
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: know an array

Post by Silvio.Falconi »

Now I correct with

Code: Select all

Function ControlloMulti(aMultiplePre,nNumero,nStatus,cGuest ,cTypeDay)
   Local t
   Local lReturn :=.f.
   Local nTimes:= 0
   Local nIterations:=0
   Local   nPos := aScan(aMultiplePre, {|x| x[1]==nNumero})


   do while nPos>0
      nIterations++
      nPos := aScan(aMultiplePre, {|x| x[1]==nNumero}, nPos+1)
   enddo

   IF  nIterations >=2
      For n= 1 to Len(aMultiplePre)
         IF  aMultiplePre[n][1] = nNumero
             AaDd(aPreMulti,{nNumero,nStatus,cGuest ,cTypeDay } )
             lReturn :=.t.
   Endif
   next
  endif

   return lReturn

and it show now the two bookings for room 13

Image

but it is correct ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
Post Reply