MsgInfoEx

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 1924
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 27 times
Been thanked: 99 times
Contact:

MsgInfoEx

Post by srvet_claudio » Thu Oct 18, 2012 4:23 am

Hi all.
I developed an extended version of the MsgInfo function, is very useful for my to debug programs. This function is inspired by a similar function written by Esgici.
I hope you find it useful.
Best regards,
Claudio Soto.

Code: Select all

*******************************************************************************
* ARCHIVO:  MsgInfoEx.prg
* LENGUAJE: HMG 
* FECHA:    Setiembre 2012
* AUTOR:    Dr. CLAUDIO SOTO
* PAIS:     URUGUAY
* E-MAIL:   srvet@adinet.com.uy
* BLOG:     http://srvet.blogspot.com
*******************************************************************************

#include "hbclass.ch"
#include <hmg.ch>
// #command MsgInfo(<arg1>,<arg2>) => hb_Alert(<arg1>)


//********************************************************************************************************
// MsgInfoEx (xMsg = [Array or xVar], [cSeparator], [cTitle], [bInfoDebug = .T.|.F.])
//********************************************************************************************************

FUNCTION MsgInfoEx (xMsg, cSeparator, cTitle, bInfoDebug) 
LOCAL cMsg
   cMsg := VarToStr (xMsg, cSeparator, bInfoDebug)
   MsgInfo (cMsg, cTitle)
RETURN cMsg



//********************************************************************************************************
// VarToStr (Data = [Array or xVar], [cSeparator], [bInfoDebug = .T.|.F.])
//********************************************************************************************************

FUNCTION VarToStr (Data, cSeparator, bInfoDebug)
LOCAL i, text:="", nLen := 0
   
   cSeparator := IF (ValType(cSeparator) == "U", " ", cSeparator)
   bInfoDebug := IF (ValType(bInfoDebug) <> "L", .F., bInfoDebug)
   
   IF ValType (Data) == "A"
      nLen := LEN (Data)
      text := text + IF (bInfoDebug, " { ", "")
      FOR i = 1 TO LEN (Data)
          text := text + VarToStr (Data [i], cSeparator, bInfoDebug) + IF (i < nLen, cSeparator,"")
      NEXT
      text := text + IF (bInfoDebug, " } ", "")
   ELSEIF ValType (Data) == "B"
          text := text + IF (bInfoDebug, " {|| ", "") 
          text := text + VarToStr (EVAL(Data), cSeparator, bInfoDebug) 
          text := text + IF (bInfoDebug, " } ", "")
   ELSE
      IF ValType (Data) == "C" .OR. ValType (Data) == "M"
         text := text + Data 
      ELSEIF ValType (Data) == "D"
         text := text + DTOC (Data)
      ELSEIF ValType (Data) == "L"
         text := text + IF (Data, ".T.",".F.")
      ELSEIF ValType (Data) == "N"
         text := text + ALLTRIM(STR(Data, 18, LENNUM(Data) - LENNUM(INT(Data)) -1))
      ELSEIF ValType (Data) == "U"
         text := text + "NIL"
      ELSEIF ValType (Data) == "O"
         text := text + "::Object::"
      ELSE
         text := text + "|Unknown Data|"
      ENDIF
   ENDIF
RETURN text



***************************************************************************************
* Example
***************************************************************************************

FUNCTION Main
   SET DATE TO BRITISH
   SET CENTURY ON
   
   aWHITE := {255,255,255}
   aBLACK := {  0,  0,  0}
   
   aMat := {{aWHITE, aBLACK},;
            { 10, 20, 30, 40, 50},;
            {{100, {"Hello", aWHITE, "HMG"}}, {200, 300, 400}},;
            {{},NIL}};
   
   MsgInfoEx ({"Desktop Width = ", GetDesktopWidth(), "Desktop Height = ", GetDesktopHeight()}, ,"Test1", .F.)
   MsgInfoEx (aMat, ", " ,"Test2", .T.)
   MsgInfoEx ({15, 20, date(), 23.5, "Hello", aBLACK, {10,12,aWHITE}, {||10*2+1}}, " , " ,"Test3", .T.)
   MsgInfoEx ({13.9999, {|| 10 < 12}, NIL, aWHITE}, NIL ,"Test4")
   MsgInfoEx (13.9999, NIL ,"Test5")

   oTest := ClassTest()
   oTest:GetSetValue (100)
   oTest:lFlag := .T.
   MsgInfoEx ({oTest, oTest:GetSetValue(), oTest:GetSetValue(200), oTest:lFlag, oTest:lFlag:=.F.}, "  -  ","Test6")

   cMsg := VarToStr({oTest, oTest:GetSetValue(), oTest:lFlag, "Hello World", aWHITE, 21.33}, " , ", .T.)
   MsgInfo (cMsg, "Test7")
   
RETURN


CLASS ClassTest 
   DATA   Value         INIT   0   PROTECTED
   DATA   lFlag         INIT  .F.
   METHOD GetSetValue   SETGET
ENDCLASS

METHOD GetSetValue (Arg) CLASS ClassTest
   IF PCOUNT() == 0
      RETURN ::Value
   ELSE
      ::Value := Arg
   ENDIF
RETURN  
Attachments
MsgInfoEx_Test.jpg
MsgInfoEx_Test.jpg (46.61 KiB) Viewed 1923 times
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Rathinagiri
Posts: 5130
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 115 times
Been thanked: 115 times
Contact:

Post by Rathinagiri » Thu Oct 18, 2012 4:40 am

Very useful Claudio.

My small suggestion. It is regarding the usage of Do Case..Endcase instead of IF.

Code: Select all

   DO CASE
   CASE ValType (Data) == "A"
      nLen := LEN (Data)
      text := text + IF (bInfoDebug, " { ", "")
      FOR i = 1 TO LEN (Data)
          text := text + VarToStr (Data [i], cSeparator, bInfoDebug) + IF (i < nLen, cSeparator,"")
      NEXT
      text := text + IF (bInfoDebug, " } ", "")
   CASE ValType (Data) == "B"
          text := text + IF (bInfoDebug, " {|| ", "")
          text := text + VarToStr (EVAL(Data), cSeparator, bInfoDebug)
          text := text + IF (bInfoDebug, " } ", "")
   CASE ValType (Data) == "C" .OR. ValType (Data) == "M"
         text := text + Data
   CASE ValType (Data) == "D"
         text := text + DTOC (Data)
   CASE ValType (Data) == "L"
         text := text + IF (Data, ".T.",".F.")
   CASE ValType (Data) == "N"
         text := text + ALLTRIM(STR(Data, 18, LENNUM(Data) - LENNUM(INT(Data)) -1))
   CASE ValType (Data) == "U"
         text := text + "NIL"
   CASE ValType (Data) == "O"
         text := text + "::Object::"
   OTHERWISE
         text := text + "|Unknown Data|"
   ENDCASE
This will some what speedup.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
danielmaximiliano
Posts: 2025
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 60 times
Been thanked: 11 times
Contact:

Post by danielmaximiliano » Thu Oct 18, 2012 4:42 am

Excelente como siempre Claudio.
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. : +54901169026142
Telegram Name : DaNiElMaXiMiLiAnO

User avatar
mol
Posts: 2775
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 106 times
Been thanked: 41 times
Contact:

Post by mol » Thu Oct 18, 2012 5:36 am

You can use hb_valtoexp() function, too.
I'm using my DebugMsg() function:

Code: Select all

function DebugMSG
	local i, aTemp := {}
	
	for i := 1 to pcount()
		aadd( aTemp, hb_PValue(i))
	next i
	msgbox(hb_valtoexp(aTemp), "Debug Informations")
 return

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

Post by esgici » Thu Oct 18, 2012 8:39 am

Hi Dr.

Your program is very useful and informative, thanks :)

I like your coding style; simple but effective, easy to read and easy to understand.

My recent message function for debug purpose is:

Code: Select all

#define Msg( xValue ) MsgBox( HB_ValToExp( xValue ) )
By the way, your hat is very cute, is this chapeau de gaucho ?

Saludos cordiales
gaucho.jpg
For who don't know what is "gaucho" and "chapeau"
gaucho.jpg (26.28 KiB) Viewed 1897 times
Viva INTERNATIONAL HMG :D

User avatar
srvet_claudio
Posts: 1924
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 27 times
Been thanked: 99 times
Contact:

Post by srvet_claudio » Thu Oct 18, 2012 1:18 pm

rathinagiri wrote:My small suggestion
Very cool, I love :D
mol wrote:I'm using my DebugMsg() function:
esgici wrote:My recent message function for debug purpose is:
Wow :o , is the best!!! :D
did not know the function HB_ValToExp() :oops:
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
srvet_claudio
Posts: 1924
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 27 times
Been thanked: 99 times
Contact:

Post by srvet_claudio » Thu Oct 18, 2012 1:26 pm

esgici wrote: your hat is very cute, is this chapeau de gaucho ?
Yes, it is a typical gaucho hat.
To follow photo of a real gaucho :lol: :lol: :lol:
Attachments
gaucho.JPG
gaucho.JPG (40.21 KiB) Viewed 1862 times
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

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

Post by esgici » Thu Oct 18, 2012 1:39 pm

srvet_claudio wrote: To follow photo of a real gaucho :lol: :lol: :lol:
Wow :o

Not only real, at the same time successful :arrow:

Do you use extra chemicals into food of your "products" ?

Certainly you are successful as grazier as a programmer.

Best reagrds
Viva INTERNATIONAL HMG :D

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

Post by esgici » Thu Oct 18, 2012 1:43 pm

srvet_claudio wrote: did not know the function HB_ValToExp()
Me too, learned from Marek :)

This is one of beauty ( very rare ;) ) of internet !

Regards
Viva INTERNATIONAL HMG :D

User avatar
mol
Posts: 2775
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 106 times
Been thanked: 41 times
Contact:

Post by mol » Thu Oct 18, 2012 5:48 pm

I'm happy my knowledge (I don't remember from who :lol: :lol: :lol: ) was useful for you!

Post Reply