Read Text Files & Codes In Startrek Style (Gregory Filatof)

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by Agil Abdullah »

Hi All,
I modified a lot to a sample module of a Text-File-Reader. It is originally made by Gregory Filatof.
I consider it very useful for programmers like me, when in time of writing codes.

With modification, now we have wider options we're familiar with:

1) Select: file types only for *.prg, *.prn, *.txt, *.rc, *.bat, *.fmg, *.hbp, *.hbc, *.*
2) Select: show line-number (Yes/No)
3) Select: Show [from] line-number [until] line-number
4) Select: Edit Mode [Yes/No] Note: only edit text in edit-box, no change to text-file.
5) Enjoy the look of classic console popular in period of early 1980 [PC-XT & Mainframe].
6) Enjoy little Jokes about "StarTrek" movie, Mr.Spock, and the Green Console [LOL].

Hi Friends... Frequently, we need to compare two *.prg or two proc/func because they're very-very similiar.
They are same in design, in logic, and in handle.
Thye differ only in file-names, in field-names, in variable-names.
In this case, when the 1st *.PRG runs well, but the 2nd *.PRG in problem, we're very busy having a look on both.

"I wrote the codes exactly the same in logic & flowchart."
"But, why the 1st runs but the 2nd fails?. Why? What's wrong?"

We're forced to go to the two block of codes, go to and go back again & again (vice-versa) several times, just to find little code error.
If we use Notepade++ , we're not allowed to run it on two windows (multiple-run).
Any teks-editor software may endanger our files when accidental edit occurs by our own hands.

In this case we need TEXT-READER with (a) independent window, (b) safe to operate, (c) help compare the content of two files), or
two block of codes, ect.

Hope this useful. Many thanks to Gregory Filatof (HMG EE).

"Salam Hangat" from Jakarta

***N.B.: I wrote this post from Readtext.exe
Attachments
ReadStartrek.png
ReadStartrek.png (197.65 KiB) Viewed 4598 times
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by esgici »

Agil Abdullah wrote: ...
"I wrote the codes exactly the same in logic & flowchart."
"But, why the 1st runs but the 2nd fails?. Why? What's wrong?"
...
Hi Agil

What we can say without seen your code ?

Probably I understood wrong your post; :(
would be more clear please :?

By the way, we have a lot of other methods for read / manipulate plain text file;
did you made a search ?

Regards
Viva INTERNATIONAL HMG :D
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by Agil Abdullah »

Here are the codes:

Code: Select all

//**[ReadText.prg]*********************************************************** 
//* by Gregory Filatof, HMGforum, Tue Jul 01, 2014 9:20 am
//* Modified by Agil Abdullah Albatati, Jakarta, HMGforum.com, 31-oct-2014
//* Make it look classic just like console in PC-TX & Mainframe in early 1980
//* StarTrek Style Console!
//***************************************************************************
#include <hmg.ch>
#define CRLF chr(13)+chr(10)

************************

Function Main()
  Local cTextFile:= ""
  Local cText    := "["+strzero(1,4)+"] " +"Dear, Ladies and Gentlement on Galaxy Planet." +CRLF +;
                           "["+strzero(2,4)+"] " +"From the cabin of Mr.Spock's Spacecraft at Mars Planet." +CRLF+;
                           "["+strzero(3,4)+"] " +"Please welcome the return of historical classic console monitor of:" +CRLF+;
                           "["+strzero(4,4)+"] " +"The IBM PC-XT(s)" + CRLF +;
			   "["+strzero(5,4)+"] " +"The Mainframe(s)" + CRLF +;
			   "["+strzero(6,4)+"] " +"The Workstation(s)" + CRLF +;
                           "["+strzero(7,4)+"] " +"The Startrek Style" + CRLF + ;
                           "["+strzero(8,4)+"] " +"Green on Black...or...Whyte on Green." + CRLF +;
                           "["+strzero(9,4)+"] " +"Thank you...! Thank you...! Thank you...!" + CRLF

  DEFINE WINDOW MainForm ;
      AT 90,20            ;
      WIDTH 1000          ;
      HEIGHT 375          ;
      TITLE 'Text Reader' ;            
     MAIN                ;
     TOPMOST             ;
     BACKCOLOR BLACK
   
   DEFINE MAIN Menu of MainForm
      DEFINE POPUP "&File"
         SEPARATOR
		 MENUITEM "Select File" ACTION DoList()
	 SEPARATOR
		 MENUITEM "Select Edit Console Color To White On Green" ACTION ChangeColor(2)
	 SEPARATOR
		 MENUITEM "Select Edit Console Color To Green On Black" ACTION ChangeColor(1)
         SEPARATOR
     END POPUP
     DEFINE POPUP "&Connect Mr.Spock"
		 MENUITEM "Connect Mr.Spock via Internet" ACTION Msgexclamation("Hi, You...! "+CRLF+;
		 "Mr.Spock is watching Star Wars movie."+CRLF+;
		 "Don't Disturb!!!"+CRLF+;
		 "[LOL]")
      END POPUP
      DEFINE POPUP "&About"
		 MENUITEM "Information from Mr.Spock" ACTION ;
	 	                 MsgStop("Ladies and Gentement...." + CRLF +;
				  "This program is to read text file whithout endanger the file. "+CRLF+;
		                 "Presented in the look of classical console in period of early 1980." + CRLF +;
				  "Mr.Spock [of The StarTrek] is scheduled to confirm this information." +CRLF +;
				  "He will confirm next spring, in the morning, if nothing special happening." +CRLF +;
				  "Thank you... Thank you... Thank you. [LOL]")
       END POPUP
       DEFINE POPUP "E&xit"
                 MENUITEM "Exit"        ACTION ThisWindow.Release
      END POPUP
   END MENU

   @ 005,005 EDITBOX Edit_1     ;
         WIDTH 960 HEIGHT 300   ;
		 VALUE cText            ;
		 BackColor BLACK        ;
                 FontColor GREEN        ;
		 DISABLEDBACKCOLOR BLACK;
                 DISABLEDFONTCOLOR GREEN;
		 FONT "Courier New" SIZE 10
   
END WINDOW       

//-MainForm.Edit_1.BackColor         := BLACK
//-MainForm.Edit_1.FontColor         := GREEN
MainForm.Center
MainForm.Activate

Return NIL
//-----------------------
Function ChangeColor(n)
      MainForm.Edit_1.BackColor         := if(n=1,BLACK, {0,100,0})                                  //--black or dark green
      MainForm.Edit_1.FontColor         := if(n=1,GREEN,WHITE)
//    MainForm.Edit_1.DisabledBackColor  := if(n=1,BLACK, {0,100,0})                                  //--black or dark green
//    MainForm.Edit_1.DisabledFontColor  := if(n=1,GREEN,WHITE)
//    msginfo("Select "+str(n,1)+" Change color is finished")
Return
*
Function Dolist()
Local cTextFile
local cList, n, nTokens, cInitWinTitle
local cStr:="", nBytes, aSelect

    cTextFile := Getfile ( { {'Text Files *.prg', '*.prg'}, ;
	                            {'Text Files *.bat', '*.bat'}, ;
				    {'Text Files *.txt', '*.txt'}, ;
				    {'Text Files *.prn', '*.prn'}, ;
				    {'Text Files *.fmg', '*.fmg'}, ;
				    {'Text Files *.rc',  '*.rc'},  ;
				    {'Text Files *.hbp', '*.hbp'}, ;
				    {'Text Files *.hbc', '*.hbc'}, ;
				    {'All Files', '*.*'}} , ;
                                    'Open File(s)' , GetCurrentFolder() , .f. , .t. )

if !file(cTextFile)
        MsgStop("File "+cTextFile+" not found!")
             Return NIL
endif

cList            := memoread(cTextFile)
nTokens       := numtoken(cList,CRLF)
nBytes          := len(cList)
cInitWinTitle:= MainForm.TITLE

MainForm.TITLE := "Text Read:" +cTextFile+"->"+ alltrim(str(nBytes))+"bytes->" + alltrim(str(nTokens))+"Totallines"
aSelect              := InputWindow( "->" + alltrim(str(nTokens))+"Lines"+"<-" ,;                                                                          //Title
                                                      {"+LineNumber?", "FromLine#", "TillLine#", "TestFirst?", "Edit Text?"}, ;                             //Headers
			                             {.F., 1, nTokens, .F., .F.}, ;                                                                                            //Init values
				                    {NIL, "9999", "9999", NIL, NIL })                                                                                      //Input format/mask
if aSelect[1]=NIL                                                                                                                                                   //--CANCEL is pressed
        MainForm.TITLE := cInitWinTitle
            return
endif
MainForm.TITLE := "Text Read:" +cTextFile+"->"+ alltrim(str(nBytes))+"bytes->" + alltrim(str(nTokens))+"lines->"+;
                              "Showing->"+alltrim(str(aSelect[2],4))+"-"+alltrim(str(aSelect[3],4))
MainForm.Edit_1.READONLY := !aSelect[5]

For n := 1 to nTokens
    if n >= aSelect[2] .and. n <= aSelect[3]
	      cDir := token(cList,CRLF,n)                                                     
	      if aSelect[4]=.T.                                                                                                                   //--Test to show first
		     aSelect[4]:= msgyesno("["+strzero(n,4)+"] "+token(cList,CRLF,n)+" CONTINUE test?")
	      endif
              cStr := cStr + if( aSelect[1]=.T., "["+strzero(n,4) + "] ", "") + cDir + CRLF     
              MainForm.Edit_1.Value    := cStr
             MainForm.Edit_1.Caretpos := len(MainForm.Edit_1.Value)-1
             do events
    endif
Next
                                                
INSERT_CTRL_END()
Return NIL
//-------------------
Function strzero(nNum,nLen)
return right(replicate("0",nLen)+ltrim(token(str(nNum),".",1)),nLen)
//-------------------
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

HB_FUNC( INSERT_CTRL_END )
{
   keybd_event(
                      VK_CONTROL,                     // virtual-key code
                                        0,                    // hardware scan code
                                       0,                    // flags specifying various function options
                                       0                     // additional data associated with keystroke
                                        );

   keybd_event(
                     VK_END   ,                   // virtual-key code
                                 0,                    // hardware scan code
                                 0,                    // flags specifying various function options
                                 0                     // additional data associated with keystroke
                                 );

   keybd_event(
      VK_CONTROL,                           // virtual-key code
                               0,                     // hardware scan code
      KEYEVENTF_KEYUP,                     // flags specifying various function options
                                0                      // additional data associated with keystroke
                               );
                                }

#pragma ENDDUMP
//-theend-
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by Agil Abdullah »

Hi Agil

What we can say without seen your code ?
I am sorry, the codes is written down next post. you can see now. Thanks :)
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by Javier Tovar »

Gracias Agil por compartir!

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

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by esgici »

Agil Abdullah wrote:Here are the codes:
...
Hi Agil

Though I'm not sure that I understood right your question, slightly modified your .prg:

Code: Select all

//**[ReadText.prg]*********************************************************** 
//* by Gregory Filatof, HMGforum, Tue Jul 01, 2014 9:20 am
//* Modified by Agil Abdullah Albatati, Jakarta, HMGforum.com, 31-oct-2014
//* Make it look classic just like console in PC-TX & Mainframe in early 1980
//* StarTrek Style Console!
//***************************************************************************
#include <hmg.ch>
#define CRLF chr(13)+chr(10)

************************

Function Main()
  Local cTextFile:= ""
  
  Local cText    := "["+strzero(1,4)+"] " + "Dear, Ladies and Gentlement on Galaxy Planet." +CRLF +;
                    "["+strzero(2,4)+"] " + "From the cabin of Mr.Spock's Spacecraft at Mars Planet." +CRLF+;
                    "["+strzero(3,4)+"] " + "Please welcome the return of historical classic console monitor of:" +CRLF+;
                    "["+strzero(4,4)+"] " + "The IBM PC-XT(s)" + CRLF +;
                    "["+strzero(5,4)+"] " + "The Mainframe(s)" + CRLF +;
                    "["+strzero(6,4)+"] " + "The Workstation(s)" + CRLF +;
                    "["+strzero(7,4)+"] " + "The Startrek Style" + CRLF + ;
                    "["+strzero(8,4)+"] " + "Green on Black...or...Whyte on Green." + CRLF +;
                    "["+strzero(9,4)+"] " + "Thank you...! Thank you...! Thank you...!" + CRLF

  DEFINE WINDOW MainForm ;
      AT 90,20            ;
      WIDTH 1000          ;
      HEIGHT 375          ;
      TITLE 'Text Reader' ;            
      MAIN                ;
      TOPMOST             ;
      ON INIT ReplaceText( cText ) ;              // <== Added
      BACKCOLOR BLACK
   
      DEFINE MAIN Menu of MainForm
      
         DEFINE POPUP "&File"
            SEPARATOR
            MENUITEM "Select File" ACTION DoList()
            SEPARATOR
            MENUITEM "Select Edit Console Color To White On Green" ACTION ChangeColor(2)
            SEPARATOR
            MENUITEM "Select Edit Console Color To Green On Black" ACTION ChangeColor(1)
            SEPARATOR
         END POPUP
        
         DEFINE POPUP "&Connect Mr.Spock"
            MENUITEM "Connect Mr.Spock via Internet" ACTION Msgexclamation("Hi, You...! "+CRLF+;
                     "Mr.Spock is watching Star Wars movie."+CRLF+;
                     "Don't Disturb!!!"+CRLF+;
                     "[LOL]")
         END POPUP
         
         DEFINE POPUP "&About"
            MENUITEM "Information from Mr.Spock" ACTION ;
                      MsgStop("Ladies and Gentement...." + CRLF +;
                     "This program is to read text file whithout endanger the file. "+CRLF+;
                     "Presented in the look of classical console in period of early 1980." + CRLF +;
                     "Mr.Spock [of The StarTrek] is scheduled to confirm this information." +CRLF +;
                     "He will confirm next spring, in the morning, if nothing special happening." +CRLF +;
                     "Thank you... Thank you... Thank you. [LOL]")
          END POPUP
          
          DEFINE POPUP "E&xit"
               MENUITEM "Exit"        ACTION ThisWindow.Release
         END POPUP
         
      END MENU
      
      @ 005,005 EDITBOX Edit_1     ;
                WIDTH 960 HEIGHT 300   ;   //   VALUE cText            ;     <== extracted  ( maybe left intact ) 
                BackColor BLACK        ;
                FontColor GREEN        ;
                DISABLEDBACKCOLOR BLACK;
                DISABLEDFONTCOLOR GREEN;
                FONT "Courier New" SIZE 10
      
   END WINDOW       

//-MainForm.Edit_1.BackColor         := BLACK
//-MainForm.Edit_1.FontColor         := GREEN

   MainForm.Center
   MainForm.Activate

Return NIL

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

PROCEDURE ReplaceText( cText2Replace )                         // <== Added
   MainForm.Edit_1.Value := cText2Replace
   INSERT_CTRL_END()
RETURN // ReplaceText()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.

//-----------------------
Function ChangeColor(n)
      MainForm.Edit_1.BackColor         := if(n=1,BLACK, {0,100,0})                                  //--black or dark green
      MainForm.Edit_1.FontColor         := if(n=1,GREEN,WHITE)
//    MainForm.Edit_1.DisabledBackColor  := if(n=1,BLACK, {0,100,0})                                  //--black or dark green
//    MainForm.Edit_1.DisabledFontColor  := if(n=1,GREEN,WHITE)
//    msginfo("Select "+str(n,1)+" Change color is finished")
Return
*
Function Dolist()

   Local cTextFile
   local cList, n, nTokens, cInitWinTitle
   local cStr:="", nBytes, aSelect

    cTextFile := Getfile ( { {'Text Files *.prg', '*.prg'}, ;
                             {'Text Files *.bat', '*.bat'}, ;
                {'Text Files *.txt', '*.txt'}, ;
                {'Text Files *.prn', '*.prn'}, ;
                {'Text Files *.fmg', '*.fmg'}, ;
                {'Text Files *.rc',  '*.rc'},  ;
                {'Text Files *.hbp', '*.hbp'}, ;
                {'Text Files *.hbc', '*.hbc'}, ;
                {'All Files', '*.*'}} , ;
                                    'Open File(s)' , GetCurrentFolder() , .f. , .t. )

   if !file(cTextFile)
      MsgStop("File "+cTextFile+" not found!")
      Return NIL
   endif

   cList         := memoread(cTextFile)
   nTokens       := numtoken(cList,CRLF)
   nBytes        := len(cList)
   cInitWinTitle := MainForm.TITLE

   MainForm.TITLE := "Text Read:" +cTextFile+"->"+ alltrim(str(nBytes))+"bytes->" + alltrim(str(nTokens))+"Totallines"
   aSelect        := InputWindow( "->" + alltrim(str(nTokens))+"Lines"+"<-" ,;    //Title                                                                 
                                      {"+LineNumber?", "FromLine#", "TillLine#", "TestFirst?", "Edit Text?"},; //Headers
                                      {.F., 1, nTokens, .F., .F.}, ;                                                                                            //Init values
                                      {NIL, "9999", "9999", NIL, NIL })                                                                                      //Input format/mask
   if aSelect[1] = NIL                                                                                                                                                   //--CANCEL is pressed
      MainForm.TITLE := cInitWinTitle
      return
   endif
   
   MainForm.TITLE := "Text Read:" +cTextFile+"->"+ alltrim(str(nBytes))+"bytes->" + alltrim(str(nTokens))+"lines->"+;
                     "Showing->"+alltrim(str(aSelect[2],4))+"-"+alltrim(str(aSelect[3],4))
   MainForm.Edit_1.READONLY := !aSelect[5]

   For n := 1 to nTokens
       if n >= aSelect[2] .and. n <= aSelect[3]
            cDir := token(cList,CRLF,n)                                                     
            if aSelect[4]=.T.                                                                                     //-- Test to show first
              aSelect[4]:= msgyesno("["+strzero(n,4)+"] "+token(cList,CRLF,n)+" CONTINUE test?")
            endif
                 cStr := cStr + if( aSelect[1]=.T., "["+strzero(n,4) + "] ", "") + cDir + CRLF     
                 MainForm.Edit_1.Value    := cStr
                MainForm.Edit_1.Caretpos := len(MainForm.Edit_1.Value)-1
                do events
       endif
   Next
                                                
   INSERT_CTRL_END()

Return NIL

//-------------------
Function strzero(nNum,nLen)
return right(replicate("0",nLen)+ltrim(token(str(nNum),".",1)),nLen)

//-------------------
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

HB_FUNC( INSERT_CTRL_END )
{
   keybd_event(
                      VK_CONTROL,                     // virtual-key code
                                        0,                    // hardware scan code
                                       0,                    // flags specifying various function options
                                       0                     // additional data associated with keystroke
                                        );

   keybd_event(
                     VK_END   ,                   // virtual-key code
                                 0,                    // hardware scan code
                                 0,                    // flags specifying various function options
                                 0                     // additional data associated with keystroke
                                 );

   keybd_event(
      VK_CONTROL,                           // virtual-key code
                               0,                     // hardware scan code
      KEYEVENTF_KEYUP,                     // flags specifying various function options
                                0                      // additional data associated with keystroke
                               );
                                }

#pragma ENDDUMP
//-theend-
I hope that this will be useful to you.

Regards
Viva INTERNATIONAL HMG :D
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by Agil Abdullah »

Many thanks for codes added, it looks nicer.
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Read Text Files & Codes In Startrek Style (Gregory Filatof)

Post by esgici »

esgici wrote: ... we have a lot of other methods for read / manipulate plain text file;
...
An example.

TIA
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

GUI or not GUI

Post by esgici »

Screen shoot of ShipLog
Screen shoot of ShipLog
ShipLog.PNG (15.7 KiB) Viewed 4454 times
Shiplog.zip
ShipLog prg & data
(572 Bytes) Downloaded 224 times
TIA
Viva INTERNATIONAL HMG :D
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: GUI or not GUI

Post by esgici »

Well,

this is the second version :
ShipLog02.PNG
ShipLog02.PNG (6.44 KiB) Viewed 4430 times

Code: Select all

  CRLF := CHR( 13 ) + CHR( 10 )
  SETCOLOR( "G/N" ) // W/G
  KEYBOARD CHR( 30 ) + CHR( 13 )
  HB_MEMOWRIT( "SHIP.LOG", MEMOEDIT( MEMOREAD( "SHIP.LOG"  ) ) 
TIA
Viva INTERNATIONAL HMG :D
Post Reply