AT() with 3 Parameter.

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

AT() with 3 Parameter.

Post 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
have fun
Jimmy
Red2
Posts: 271
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: AT() with 3 Parameter.

Post 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
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: AT() with 3 Parameter.

Post 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 ) )
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: AT() with 3 Parameter.

Post 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
have fun
Jimmy
User avatar
dragancesu
Posts: 920
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: AT() with 3 Parameter.

Post by dragancesu »

edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: AT() with 3 Parameter.

Post 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
Last edited by edk on Wed Oct 23, 2019 9:51 am, edited 1 time in total.
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: AT() with 3 Parameter.

Post 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
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: AT() with 3 Parameter.

Post 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
Regards,

Anand

Image
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: AT() with 3 Parameter.

Post 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 :?:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: AT() with 3 Parameter.

Post 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 :?:
have fun
Jimmy
Post Reply