Need to open and read text file.

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

NickSteel
Posts: 67
Joined: Mon May 27, 2013 10:44 pm

Re: Need to open and read text file.

Post by NickSteel »

Found this to parse delimited text to an array. Looks good.

https://www.tek-tips.com/viewthread.cfm?qid=87443

I think I have about all the stuff I need for now.

Thanks Guys!
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Need to open and read text file.

Post by esgici »

Code: Select all

HB_ATokens()
Splits a string into tokens based on a delimiter. 
Syntax
HB_ATokens( <cString>          , ;
           [<cDelimiter>]      , ;
           [<lSkipQuotes>]     , ;
           [<lDoubleQuotesOnly>] ) --> aTokens

Arguments
<cString> 
This is a character string which is tokenized based on the value of <cDelimiter>. 
<cDelimiter> 
A single character can be specified as delimiter used to tokenize the string <cString>. It defaults to a blank space (Chr(32)). 
<lSkipQuotes> 
This parameter defaults to .F. (false). When it is set to .T. (true), all portions of <cString> enclosed in single or double quotes are not searched for <cDelimiter>. 
<lDoubleQuoteOnly> 
The parameter is only relevant when <lSkipQuotes> is .T. (true). When <lDoubleQuoteOnly> is also .T. (true), only portion sof <cString> enclosed in double quotes are not searched for <cDelimiter>. Return
The function returns an array of character strings. 
Description
HB_ATokens() function splits <cString> into substrings, based on the value of <cDelimiter>. The delimiter is removed from <cString> and the resulting substrings are collected in an array, which is returned. 
If <lSkipQuotes> is .T. (true), a quoted substring within <cString> is not split if it contains the delimiter sign. If the value of <lSkipQuotes> is .F. (false), which is the default, the quoted substring will be split, regardless of the quotes. The <lDoubleQuoteOnly> argument specifies if both the double and single quote signs are interpreted as a quote sign (.F.) or only the double quote is recognized as a quote sign (.T.). 
Info
See also: At(), AtToken(), IN, Left(), Rat(), Right(), SubStr() 
Category: Array functions , Character functions , Token functions 
Source: vm\arrayshb.c 

Example
// The example displays the result of HB_ATokens() using different
// combinations for <lSkipQuotes> and <lDoubleQuoteOnly>

   PROCEDURE Main
      LOCAL cString := [This\'_is\'_a_tok"e_n"ized_string]
      LOCAL aTokens := {}
      LOCAL i

      aTokens := HB_ATokens( cString, "_", .F., .F. )

      FOR i := 1 TO Len( aTokens )
         ? aTokens[i]
      NEXT
      // Result: array with 6 elements
      // This\'
      // is\'
      // a
      // tok"e
      // n"ized
      // string

      aTokens := HB_ATokens( cString, "_", .T., .F. )

      FOR i := 1 TO Len( aTokens )
         ? aTokens[i]
      NEXT
      // Result: array with 4 elements
      // This\'_is\'
      // a
      // tok"e_n"ized
      // string

      aTokens := HB_ATokens( cString, "_", .T., .T. )

      FOR i := 1 TO Len( aTokens )
         ? aTokens[i]
      NEXT
      // Result: array with 5 elements
      // This\'
      // is\'
      // a
      // tok"e_n"ized
      // string
   RETURN
Viva INTERNATIONAL HMG :D
NickSteel
Posts: 67
Joined: Mon May 27, 2013 10:44 pm

Re: Need to open and read text file.

Post by NickSteel »

Neat!

I have enough code to tweak into what I need. Really love the Forum and all the expert advice. :D
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Need to open and read text file.

Post by Pablo César »

srvet_claudio wrote:Since version HMG.3.1.3

Code: Select all

MsgDebug ( xData1, xData2, ... )  --> Accepts as a parameters any data type, elements or objects.
Returns a string with the message displayed on the screen.
 
Example:
Num   := 10
aData := { "Number", 38, "aRGB", YELLOW, "Hello" }
cMsg  := MsgDebug ( TIME(), aData, {|| NIL}, Num == 3 )
Dear Claudio, may you accept a suggestion in order to take place TITLE for msgbox (at first parameter as optional) in your very usefull MsgDebug function ?

Please note this code:

Code: Select all

Function MsgDebug
Local i, cMsg, nParam:=PCount(), nStart:=1, cTit:="DEBUG INFO"

If nParam>1 .and. ValType(PValue(1))="C"
   nStart:=2
   cTit:=PValue(1)
Endif
cMsg := "Called from: " + ProcName(1) + "(" + LTrim(Str(ProcLine(1))) + ") --> " + ProcFile(1) + CRLF + CRLF
For i = nStart To nParam
    cMsg := cMsg + hb_ValToExp(PValue(i)) + IIf (i < nParam, ", ", "")
Next
MsgBox(cMsg, cTit)
Return cMsg
This would accepts the first parameter as title of MsgDebug and will works as optional. And also change MsgInfo by MsgBox (without any Icon, my opinion)

What do you think, Claudio ? Can it be adopted this change in MsgDebug ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Need to open and read text file.

Post by bpd2000 »

I also suggest for change for title as first parameter as title of MsgDebug

Further MsgDebug to be renamed to DebugInfo ?
BPD
Convert Dream into Reality through HMG
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Need to open and read text file.

Post by Pablo César »

bpd2000 wrote:I also suggest for change for title as first parameter as title of MsgDebug
Thanks Dave for your interest. :)
Further MsgDebug to be renamed to DebugInfo ?
Ohhh no... both functions must be separated as different modes. Also note I suggest to replace MsgInfo fo MsgBox at MsgDebug function.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2224
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Need to open and read text file.

Post by srvet_claudio »

Pablo César wrote: This would accepts the first parameter as title of MsgDebug and will works as optional. And also change MsgInfo by MsgBox (without any Icon, my opinion)
What do you think, Claudio ? Can it be adopted this change in MsgDebug ?
Hi Pablo.
Change MsgInfo by MsgBox: it's good idea.

First parameter as title: I believe that this is not the best solution because MsgDebug is a function for use internal and fast and easy, without having to think about the type or the order of the parameters.
Maybe with some global variable could be arranged with use of the #translate, e.g.

MSGDEBUG [ TITLE cTitle ] [ PARAMETERS ] par1, par2, ... , parN [STOREIN cMsg]
Best regards.
Dr. Claudio Soto
(from Uruguay)
https://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Need to open and read text file.

Post by Pablo César »

srvet_claudio wrote:Maybe with some global variable could be arranged with use of the #translate, e.g.

MSGDEBUG [ TITLE cTitle ] [ PARAMETERS ] par1, par2, ... , parN [STOREIN cMsg]
Better idea !! Thanks Claudio ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Need to open and read text file.

Post by Pablo César »

Dear Claudio,

I have make many test with long strings and as always I do, I use your blessed function MsgDebug. But sometimes, strings and arrays are so long that I can not visualize all items completly.

Is it possible to add a kind of EditBox (but not editable) with scrollbars, so you can scroll the screen and also would select some text on the screen ?. That would help a lot.

I saw something similar at "Build log" button of current IDE. Leveraging the subject: I noted that EditBox is allowing to edit text of log. Is this was supposed to work like this ?

Thanks for your attention, once again ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2224
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Need to open and read text file.

Post by srvet_claudio »

Pablo César wrote:Dear Claudio,

I have make many test with long strings and as always I do, I use your blessed function MsgDebug. But sometimes, strings and arrays are so long that I can not visualize all items completly.

Is it possible to add a kind of EditBox (but not editable) with scrollbars, so you can scroll the screen and also would select some text on the screen ?. That would help a lot.

I saw something similar at "Build log" button of current IDE. Leveraging the subject: I noted that EditBox is allowing to edit text of log. Is this was supposed to work like this ?

Thanks for your attention, once again ! :)
It is a good idea.
Best regards.
Dr. Claudio Soto
(from Uruguay)
https://srvet.blogspot.com
Post Reply