How to search and retrive a value

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

How to search and retrive a value

Post by RPC » 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.

User avatar
dragancesu
Posts: 477
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 3 times
Been thanked: 75 times

Post by dragancesu » Thu Nov 30, 2017 12:55 pm


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

Post by esgici » Thu Nov 30, 2017 3:03 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.
Hi Rajeev

Would you share a sample .CSV file ?

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D

jayadevu
Posts: 204
Joined: Tue May 19, 2009 7:10 am
Been thanked: 3 times

Post by jayadevu » Thu Nov 30, 2017 4:08 pm

Hi Rajeev,

Please add the following statements to your program to get an array of Rates:

if !empty( cRateFile )
aLines := HB_ATOKENS( MEMOREAD( cRateFile ), LF )
aeval(aLines,{|e| aRecord := HB_ATOKENS(e,","),;
aadd(aRates,aRecord)})
cTimeStamp := SubStr(cRateFile,RAt("_",cRateFile)+1,6)
endif

You can also use the cTimeStamp to retrieve the date portion of the file.

Are you trying to read BSE Sauda File ?

If you need any further help, get in touch with me privately.

Warm regards,

Jayadev

User avatar
BeGeS
Posts: 94
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 19 times
Been thanked: 19 times

Post by BeGeS » 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.
I get by with a little help from my friends

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

Post by serge_girard » Thu Nov 30, 2017 8:42 pm

Rajeev, Best send us (a piece) of the mentionned file in a ZIP or so.

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 8:17 am

Hi
Thanks to all of you for helping me.
I have already attached the file with jpg extension(to be converted to csv extension)
As required by serge and esgici I enclosing the same file zipped in rar format
@ dragancesu - I will look into link provided by you. Thanks
@ BeGeS - I will try your method. Thanks
@ Jaydev - Yes, I am trying to read BSE bhavcopy. I will try out your code. I will definitely contact you.Thanks
Rajeev Chavan
Attachments
EQ_ISINCODE_291117.rar
(112.01 KiB) Downloaded 22 times

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 8:19 am

Hi
Sorry to Serge and Esgici, I did not attach file earlier.
Rajeev Chavan

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

Post by esgici » Fri Dec 01, 2017 8:44 am

RPC wrote:
Fri Dec 01, 2017 8:19 am
Hi
Sorry to Serge and Esgici, I did not attach file earlier.
Rajeev Chavan
No problem friend 8-)

Happy HMGing :D
Viva INTERNATIONAL HMG :D

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

Post by serge_girard » Fri Dec 01, 2017 9:10 am

Rajaeev,
You can start with this code:

Code: Select all

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


FUNCTION MAIN()
/****************/
oFile := TFileRead():New( 'C:\TEST\EQ_ISINCODE_291117.CSV' )
oFile:Open()
IF oFile:Error()
   MSGINFO ( STR(oFile:ErrorNo()) + ' ' + oFile:ErrorMsg( "File open error" ), 'NOK')
   RETURN ''
ENDIF


DO WHILE oFile:MoreToRead()
   cLINE   := ALLTRIM(oFile:ReadLine())

   IF "INE885A01032" $ cLINE
      aLINE := HB_ATOKENS(cLINE, ','  ) 
      EXIT
   ENDIF


ENDDO
oFile:Close()
 
MSGINFO( LEN(aLINE ))
FOR a := 1 TO LEN(aLINE)
   MSGINFO( aLINE [A] )
next
Serge

Post Reply