Having trouble with AT Function Behaviour

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
User avatar
Peter
Posts: 9
Joined: Fri Feb 10, 2017 4:14 am

Having trouble with AT Function Behaviour

Post by Peter » Sun Dec 10, 2017 1:37 am

I am having trouble using the AT function. Please see the attached piece of code. The AT function consistently returns Zero.
I would deeply appreciate any help
Thanks in advance
Peter

#include <hmg.ch>

Private S11:= "", S12:= "", S21:= "", S22:= "", S31:="", S32:= ""

Private Location := "", SalaBrak := "", Nationality := "", CurEmployer := ""
Private V_Location := "", V_SalaBrak := "", V_Nationality := "", V_CurEmployer := ""

Location = "Location"
SalaBrak = "Salary Bracket"
Nationlity = "Nationality"
CurEmployer = "Current Employer"

S11 = "Location: Dubai- United Arab Emirates Salary Bracket: $2001 - $3000"
S12 = "Nationality: Romanian Current Employer: Government"

S21 = "Location: Dubai- United Arab Emirates Salary Bracket: $4001 - $5000"
S22 = "Nationality: Irish Current Employer: Seeking work in Dubai"

S31 = "Location: Dubai- United Arab Emirates Salary Bracket: $4001 - $5000"
S32 = "Nationality: British (UK) Current Employer: Not Mentioned"

Proclocationline(S11)
ProcNationalityLine(S12)

Proclocationline(S21)
ProcNationalityLine(S22)

Proclocationline(S31)
ProcNationalityLine(S32)

RETURN



Static Procedure ProcLocationLine(LineInput)
Local LocPtr := 0, LocLen := 0, SalPtr := 0, SalLen := 0
LocLen = 10
SalLen = 16
LocPtr = AT(LineInput, Location)
SalPtr = AT(LineInput, SalaBrak)
V_Location = SUBSTR(LineInput, (LocPtr + LocLen), (SalPtr - LocLen - 1))
V_SalaBrak = SUBSTR(LineInput, (SalPtr + SalLen))
RETURN
*
*
*
Static Procedure ProcNationalityLine(LineInput)
Local NatPtr := 0, NatLen:= 0, EmpPtr := 0, EmpLen := 0
NatLen = 13
EmpLen = 18
NatPtr = AT(LineInput, Nationality)
EmpPtr = AT(LineInput, CurEmployer)
V_Nationality = SUBSTR(LineInput, NatLen, (EmpPtr - NatLen))
V_CurEmployer = SUBSTR(LineInput, (EmpPtr + EmpLen))
RETURN
*

User avatar
esgici
Posts: 4446
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 332 times
Been thanked: 101 times
Contact:

Post by esgici » Sun Dec 10, 2017 3:03 am

Peter wrote:
Sun Dec 10, 2017 1:37 am
...
I am having trouble using the AT function. Please see the attached piece of code. The AT function consistently returns Zero.
...
Hi Peter

Standard format of AT() function :

Code: Select all

AT( <cSearch>, <cString>, [<nStart>], [<nEnd>] ) --> nPos
So you need swap two parameters: That is instead of

Code: Select all

LocPtr	= AT(LineInput, Location )
use

Code: Select all

LocPtr	= AT(Location, LineInput)
Happy HMG'ing :D

PS: You can find more info at here.
Viva INTERNATIONAL HMG :D

franco
Posts: 251
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Sun Dec 10, 2017 7:04 pm

Peter here is a quick example;
a = 'Hello Location: Mexico and more'
b = at('Location:', a)
c = substr(a,b+10,1000) // use 1000 not knowing length of variable
d = substr(c,1,at(' ',c))
msgbox(d) //will return Mexico
It may be easier to create a table with fields for information. Then it will be easier to find different values.
Franco:

edk
Posts: 319
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 91 times
Been thanked: 243 times

Post by edk » Sun Dec 10, 2017 8:51 pm

franco wrote:
Sun Dec 10, 2017 7:04 pm
c = substr(a,b+10,1000) // use 1000 not knowing length of variable
In this case just use c = substr(a,b+10)
As a result, we get a string "a" cutted from the character in position b+10 up to the end of the string.

franco
Posts: 251
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 9 times

Post by franco » Mon Dec 11, 2017 1:40 am

Thank`s Edward I did not know this.

Post Reply