operador In

operador In

Postby goosfancito » Sun Feb 21, 2021 11:28 pm

Hola.

Code: Select all  Expand view

local aDatos:={1,2,3}
if (x in aDatos)
   ? "esta"
endif
 

eso al ejecutarlo me da un error de argumento, que hago mal?
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: operador In

Postby jvtecheto » Mon Feb 22, 2021 9:53 am

Hola Gustavo.

El operador In ahora me entero que existe en Harbour, creo poder afirmar que en Clipper no existia.

si fueran cadenas podrias utilizar el operador $

de la forma

Code: Select all  Expand view

   local x := "a"
   local aDatos := "abc"
    if (x $ aDatos)
       ? "esta"
    endif

 


pero con numeros, como sabes puedes utilizar

Code: Select all  Expand view

   local x := 1
  local aDatos := {1,2,3}
    if (Ascan(aDatos, x)>0)
       ? "esta"
    endif
 


Saludos

Jose.
Fwh 19.06 32 bits + Harbour 3.2dev(r2104281802) + Borland 7.4 + FivEdit
User avatar
jvtecheto
 
Posts: 576
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: operador In

Postby nageswaragunupudi » Mon Feb 22, 2021 10:15 am

Code: Select all  Expand view

x IN aDatos
 

is permissible syntax in xHarbour and is very powerful.
I do not understand the reason for the runtime error, because we can use any datatype for x in this syntax.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: operador In

Postby jvtecheto » Mon Feb 22, 2021 10:59 am

Mr. Rao

I think Gustavo is using Harbour , the operator IN only exists in XHarbour

in Harbour and with arrays should uses
Code: Select all  Expand view

(Ascan(aDatos, x)>0)
 


Regards

Jose.
Fwh 19.06 32 bits + Harbour 3.2dev(r2104281802) + Borland 7.4 + FivEdit
User avatar
jvtecheto
 
Posts: 576
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: operador In

Postby karinha » Mon Feb 22, 2021 1:23 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: operador In

Postby nageswaragunupudi » Mon Feb 22, 2021 5:13 pm

I think Gustavo is using Harbour , the operator IN only exists in XHarbour

If he is using Harbour, he should get a compilation error but not runtime error.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: operador In

Postby nageswaragunupudi » Tue Feb 23, 2021 3:10 am

Now, I understand.

This sample program:
Code: Select all  Expand view
#include "fivewin.ch"
#include "hbcompat.ch"

function Main()

   local x     := 2
   local aList := { 1,2,3 }

   if ( x IN aList )
      ? "ok"
   else
      ? "not ok"
   endif

return nil

When compiled and built with xHarbour works perfectly.

When we compile with Harbour, the hbcompat.ch uses this translate to preprocess:
Code: Select all  Expand view
  #translate ( <exp1> IN <exp2> )     => ( ( <exp1> ) $ ( <exp2> ) )
 


So,
Code: Select all  Expand view

   if ( x IN aList )
 

is translated and compiled as:
Code: Select all  Expand view

if ( x $ aList )
 

This naturally results in runtime error.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 83 guests