How to search and retrive a value

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Anand
Posts: 216
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 37 times
Been thanked: 34 times

Re: How to search and retrive a value

Post by Anand » Fri Dec 01, 2017 9:22 am

serge_girard wrote:
Fri Dec 01, 2017 9:10 am
Rajaeev,
You can start with this code:
<snip code>
Serge
+1
I use similar logic in my import data from csv programs.

Rajeev, I will advise to use Serge's logic instead of memoread.

Regards,

Anand
Image

Tiger
Posts: 32
Joined: Mon Aug 31, 2015 11:28 am
Location: Taipei
Has thanked: 2 times
Been thanked: 4 times

Post by Tiger » Fri Dec 01, 2017 9:56 am

How about this ....
Please check if any better way to do that ...

// ISIN_CODE : 14th ","
// CLOSE :7th ","

#include "hmg.ch"
#Include "Fileio.CH"

FUNCTION MAIN()
/****************/
oFile := TFileRead():New( 'C:\TEST\EQ_ISINCODE_291117.CSV' )
oFile:Open()

WHILE oFile:MoreToRead()
cLINE := ALLTRIM(oFile:ReadLine())
G_ISIN=ALLTRIM(SUBSTR(cLINE,FND(",",cLINE,14)+1,FND(",",cLINE,15)-FND(",",cLINE,14)-1))
G_CLOSE=ALLTRIM(SUBSTR(cLINE,FND(",",cLINE,7)+1,FND(",",cLINE,8)-FND(",",cLINE,7)-1))
IF "INE885A01032" $ cLINE
CLOSE_PRICE== G_CLOSE
EXIT
ENDIF

ENDDO
oFile:Close()

FUNCTION FND ( cCharacter, cString, nOccurrence )
LOCAL cTempString, nPosition, cStringlen
cStringlen := Len( cString )
cTempString := cString
WHILE .T.
nPosition := At( cCharacter, cTempString )
IF nOccurrence <= 1
RETURN nPosition
ENDIF // nOccurrence <=1
cTempString := SubStr( cTempString, 1, nPosition - 1 ) + Chr( 255 ) + SubStr( cTempString, nPosition + 1, cStringlen - nPosition )
nOccurrence--
ENDDO // WHILE .T.
RETURN

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

Post by esgici » Fri Dec 01, 2017 11:37 am

Hi Rajaeev

As you seen there isn't anything inexhaustible under the sun :(

All advice of our friend are applicable and useful.

By the way, did you inspect this article ?
https://vivaclipper.wordpress.com/2014/ ... unctions/]

Regards
Viva INTERNATIONAL HMG :D

User avatar
serge_girard
Posts: 1907
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 318 times
Been thanked: 74 times
Contact:

Post by serge_girard » Fri Dec 01, 2017 1:46 pm

Old (Roman) proverbe says: All roads lead to Rome...

Serge

RPC
Posts: 119
Joined: Fri Feb 10, 2017 4:12 am
Has thanked: 28 times
Been thanked: 6 times

Post by RPC » Fri Dec 01, 2017 5:51 pm

Oh boy !
So many ways to achieve one goal.
Thanks from bottom of my heart.
Thanks Serge, Tiger and Anand. I will try out your methods also.

RPC
Posts: 119
Joined: Fri Feb 10, 2017 4:12 am
Has thanked: 28 times
Been thanked: 6 times

Post by RPC » Fri Dec 01, 2017 5:53 pm

BeGeS wrote:
Thu Nov 30, 2017 6:29 pm
RPC wrote:
Thu Nov 30, 2017 11:59 am
Hi everybody
I want to search a string(CSV file) read throuh memoread(CSV file) function.
I have to search a Code and then jump back a few commas to retrieve a value.
For eg
Consider the enclosed EQ_ISINCODE_291117.CSV file. In this I want search say code "INE885A01032" after searching that I want to jump back 6 commas to get value 804.75. To search code "INE885A01032" I use AT() function but do not know how to jump back 6 commas to get value of 804.75
Can anybody help ?
TIA
Rajeev
PS-Please note it not jpg file, please rename the file as EQ_ISINCODE_291117.CSV instead of jpg extension.
For those things I prefer to use the functions FOPEN() - FREADSTR() - FSEEK() - FCLOSE(). I have never used MEMOREAD(). But I'll tell you what I would do in your case.

Let's suppose that the string that returns MEMOREAD() we call it cCODE.
Then we could do like this:

Code: Select all

FOR H:=1 TO (LEN(cCODE)-11)

  IF SUBSTR(cCODE, H, 12)=="INE885A01032”
     K:=H
     EXIT
  ENDIF

NEXT

COMMAS:=0

FOR H:=K TO 1 STEP(-1)

  IF SUBSTR(cCODE, H, 1)==”,”
    COMMAS+=1
  ENDIF
  IF COMMAS==6 
    J:=H
    EXIT
  ENDIF

NEXT

PRICE:=VAL(SUBSTR(cCODE, J+1, 6))
This is only an idea. You have to be sure that within cCODE is the code you are looking for. And as for the commas, it may be six or seven, depending on whether you are counting the comma that precedes the INE8... code.
Hi BeGeS
I tried your code.
it works perfectly !
Many thanks

RPC
Posts: 119
Joined: Fri Feb 10, 2017 4:12 am
Has thanked: 28 times
Been thanked: 6 times

Post by RPC » Fri Dec 01, 2017 5:56 pm

esgici wrote:
Fri Dec 01, 2017 11:37 am
Hi Rajaeev

As you seen there isn't anything inexhaustible under the sun :(

All advice of our friend are applicable and useful.

By the way, did you inspect this article ?
https://vivaclipper.wordpress.com/2014/ ... unctions/]

Regards
Hi Esgici
Could you pls check the link. It is probably incorrect.
I am getting following error msg on web page
"It seems we can’t find what you’re looking for. Perhaps searching, or one of the links below, can help."
Pls provide correct link.
Many thanks

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

Post by esgici » Fri Dec 01, 2017 6:44 pm

RPC wrote:
Fri Dec 01, 2017 5:56 pm
...
Could you pls check the link. It is probably incorrect.
...
Sorry :(

https://vivaclipper.wordpress.com/2014/ ... functions/

Regards
Viva INTERNATIONAL HMG :D

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

Post by esgici » Sat Dec 02, 2017 11:24 am

My two cents :
ScreenShoot of L4VinDSVF.jpg
ScreenShoot of L4VinDSVF.jpg (34.17 KiB) Viewed 122 times
L4VinDSVF.zip
(2.23 KiB) Downloaded 28 times
Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

RPC
Posts: 119
Joined: Fri Feb 10, 2017 4:12 am
Has thanked: 28 times
Been thanked: 6 times

Post by RPC » Sun Dec 03, 2017 7:03 am

esgici wrote:
Sat Dec 02, 2017 11:24 am
My two cents :

ScreenShoot of L4VinDSVF.jpg
L4VinDSVF.zip

Happy HMG'ing :D
Wow ! Esgici
it is not two cents worth but two million dollar worth of code for me.
Another way of processing text file. I love it.
Many thanks.

Post Reply