Page 1 of 2

AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 2:00 am
by AUGE_OHR
hi,

under Xbase++ i have 3 Parameter where 3rd is optional

Code: Select all

   At( <cSubString>, <cString>, [<nStartPos>] ) --> nPosition 
here i search how often a sign is in a String

Code: Select all

FUNCTION Countat( cString, cSign )
LOCAL nRet  := 0
LOCAL nPosi := 1
LOCAL nMax  := LEN( cString )

   DO WHILE nPosi > 0
      nPosi := AT( cSign, cString, nPosi + 1 )
      IF nPosi > 0
         nRet ++
      ELSE
         EXIT
      ENDIF
   ENDDO
RETURN nRet
now i got this Error Message
C:\hmg.3.4.4\HARBOUR\contrib\gtwvg\WMP\WM9TOOLS.PRG(2057) Error E0021 Incorrect number of arguments in AT
Passed: 3, expected: 2
hm ... Clipper have only 2 Parameter
so how to add 3rd Parameter <nStartPos> :?:

Greetings Jimmy

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 2:34 am
by Red2
Hi,

I believe you are correct, AT() has only 2 parameters in HMG.

(I come from VFP. VFP has its own 3rd parameter: AT(cSearchExpression, cExpressionSearched [, nOccurrence]))

I also have had to work-around this in HMG.

Regards,
Red2

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 3:32 am
by andyglezl
Tal vez de esta manera...
*------------------------------------
Maybe this way ...

Code: Select all

   DO WHILE nPosi > 0
      nPosi := AT( cSign, cString )
      cString := SUBSTR( cString, nPosi )
      IF nPosi > 0
         nRet ++
      ELSE
         EXIT
      ENDIF
   ENDDO
Or

Code: Select all

FOR i1 = 1 TO LEN( cString )
	IF SUBSTR( cString, i1, 1 ) == "x"
		nRet ++
	ENDIF
NEXT
Or

Code: Select all

nLen1 := LEN( cString )
cString := CharRem( "x", cString )
nLen2 := LEN( cString )
nRet := nLen1 - nLen2
Or

Code: Select all

nRet := LEN( cString ) - LEN( CharRem( "x", cString ) )

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 5:57 am
by AUGE_OHR
hi,

Thx for Answer.
andyglezl wrote: Wed Oct 23, 2019 3:32 am Tal vez de esta manera...
*------------------------------------
Maybe this way ...
i did wrote a Function like you recommend but i got this

C:\hmg.3.4.4\HARBOUR\contrib\gtwvg\WMP\WM9.PRG(350) Error E0008 Redefinition of predefined function AT as 'AT'

it seems i can't "override Core" Function under harbour :?:

Greetings Jimmy

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 6:35 am
by dragancesu

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 7:20 am
by edk
AUGE_OHR wrote: Wed Oct 23, 2019 5:57 am it seems i can't "override Core" Function under harbour :?:
:idea:

Code: Select all

#include <hmg.ch>
#xtranslate AT(<cSeek>,<cString>[, <nStartPos>]) => hb_Ati( <cSeek>,<cString>, <nStartPos>)

PROCEDURE MAIN 
	msgdebug ( AT('x', 'xabcxdef', 3) )
	msgdebug ( AT('x', 'xabcxdef') )
RETURN
AUGE_OHR wrote: Wed Oct 23, 2019 2:00 am here i search how often a sign is in a String

Code: Select all

#include <hmg.ch>
#xtranslate CountAt( <cString>, <cSign> ) => hb_TokenCount( <cString>, <cSign> ) - 1

PROCEDURE MAIN 
	msgdebug ( CountAT('xabcxdef', 'x') )
	msgdebug ( CountAT('xabcxdef', 'i') )
	msgdebug ( CountAT('xabcxxdefx', 'x') )
RETURN

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 9:05 am
by SALINETAS24
andyglezl wrote: Wed Oct 23, 2019 3:32 am Tal vez de esta manera...
*------------------------------------
Maybe this way ...

Code: Select all

   DO WHILE nPosi > 0
      nPosi := AT( cSign, cString )
      cString := SUBSTR( cString, nPosi )
      IF nPosi > 0
         nRet ++
      ELSE
         EXIT
      ENDIF
   ENDDO
solo una pequeña corrección

Code: Select all

   DO WHILE nPosi > 0
      nPosi := AT( cSign, cString )
      cString := SUBSTR( cString, nPosi+1 )   //Sumar 1 a nPos, en caso contrario estará en bucle
      IF nPosi > 0
         nRet ++
      ELSE
         EXIT
      ENDIF
   ENDDO
Saludos

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 11:55 am
by Anand
edk wrote: Wed Oct 23, 2019 7:20 am
AUGE_OHR wrote: Wed Oct 23, 2019 5:57 am it seems i can't "override Core" Function under harbour :?:
:idea:

Code: Select all

#include <hmg.ch>
#xtranslate AT(<cSeek>,<cString>[, <nStartPos>]) => hb_Ati( <cSeek>,<cString>, <nStartPos>)

PROCEDURE MAIN 
	msgdebug ( AT('x', 'xabcxdef', 3) )
	msgdebug ( AT('x', 'xabcxdef') )
RETURN
AUGE_OHR wrote: Wed Oct 23, 2019 2:00 am here i search how often a sign is in a String

Code: Select all

#include <hmg.ch>
#xtranslate CountAt( <cString>, <cSign> ) => hb_TokenCount( <cString>, <cSign> ) - 1

PROCEDURE MAIN 
	msgdebug ( CountAT('xabcxdef', 'x') )
	msgdebug ( CountAT('xabcxdef', 'i') )
	msgdebug ( CountAT('xabcxxdefx', 'x') )
RETURN

Wow Edward !

You gave a solution I was also looking for as I too have Xbase++ codes. Now both HMG and Xbase++ functions will work.

Thanks a lot.

Regards,

Anand

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 9:02 pm
by AUGE_OHR
edk wrote: Wed Oct 23, 2019 7:20 am
AUGE_OHR wrote: Wed Oct 23, 2019 5:57 am it seems i can't "override Core" Function under harbour :?:
:idea:
AHA :idea:

Code: Select all

#xtranslate AT(<cSeek>,<cString>[, <nStartPos>]) => hb_Ati( <cSeek>,<cString>, <nStartPos>)
Perfect :D

Question : is hb_Ati() harbour or HMG :?:

Re: AT() with 3 Parameter.

Posted: Wed Oct 23, 2019 9:36 pm
by AUGE_OHR
ok

i saw hb_AtI() is a harbour function so i wonder why AT() will only accept 2 Parameter :?:

Question ; what is the Difference between hb_At() vs. hb_Ati() :?:

i have read Description
This function has same functionality as hb_At() with the significant difference that it's case Insensitive.

Optionally, with nStart can be defined the position into main string from where the search of cSearch must begin and with nEnd the position where it must stop. If neither of them is defined, nStart is 1st position and nEnd the ending of cString.
but i still "see" no Difference.

can someone please show me a sample where hb_At() fail while hb_Ati() work :?: