Page 1 of 1

Is there a way to change message in MsgMeter?

Posted: Wed May 29, 2019 3:27 pm
by ellano
To everyone:

I want to know if there is a simple way to change the message in a MsgMeter like in the following code:

Code: Select all

FUNCTION ReportToExcel(oBrwI, aData)

   MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
             ToExcel ( oMeter, oText, oDlg, @lEnd, oBrwI, aData) },;
             "Sending data to Excel", "Please stand by..." )
RETURN NIL

STATIC FUNCTION ToExcel( oMeter, oText, oDlg, lEnd, oBrwI, aData )

   LOCAL oExcel   := ExcelObj()
   LOCAL oBook    := oExcel:WorkBooks:Add()
   LOCAL oSheet   := oBook:ActiveSheet
   LOCAL oRange, n :=1, nRows :=  Len( aData ), nCols:= Len(aDatos[1]), oCol
...
...
/* 1st phase here ********/
   While n <= nRows .AND. ! lEnd
      oRange:Rows( n+2 ):Value  := aData[ n ]
      oMeter:Set( n++ )
   End
...
/*2nd phase here  *****
* need to change progress bar dialog message to "Getting graphs from data" */
...

   IF lEnd
      MsgAlert( "Report cancel by user", "Excel" )
   Else
      MsgInfo( Len( aData ), "Total animals in these sequence:" )
   EndIf

RETURN Nil
Thank you in advance
Emiliano Llano Dïaz

Re: Is there a way to change message in MsgMeter?

Posted: Wed May 29, 2019 8:20 pm
by karinha
Hi, look \samples\WIN32?.PRG

Regards.

Re: Is there a way to change message in MsgMeter?

Posted: Wed May 29, 2019 8:35 pm
by Silvio.Falconi
erase msgmeter and use this

Code: Select all

#include "FiveWin.ch"
#include "constant.ch"

FUNCTION ReportToExcel(oBrwI, aData)
         Local nBottom   := 8
         Local nRight    := 45
         Local nWidth :=  Max( nRight * DLG_CHARPIX_W, 180 )
         Local nHeight := nBottom * DLG_CHARPIX_H
         Local oProgress
         local oDlgProgress, oSay01, oSay02, oBmp

DEFINE DIALOG oDlgProgress SIZE nWidth, nHeight;
   TITLE 'Report to Excel' PIXEL  ;
          STYLE nOr( DS_MODALFRAME, WS_POPUP, WS_CAPTION,  4 )

   @ 1,2  BITMAP oBmp  OF oDlgProgress RESOURCE 'INDEX'   SIZE 20,20 NOBORDER
   @ 2,12 SAY oSay01  Prompt "Reporting..."   OF oDlgProgress
          oBmp:lTransparent:=.t.


    @ 2,2 SAY oSay02 PROMPT space(30)    OF oDlgProgress  SIZE 100,10
  
 oProgress := TProgress():New( 2.8, 2, oDlgProgress, , , , .f.,, 150, 15, "your first text", .f., .f. )



   oDlgProgress:bStart := { || SysRefresh(), ToExcel( oProgress , oDlgProgress lEnd, oBrwI, aData ,oSay02), oDlgProgress:End() }

   ACTIVATE DIALOG oDlgProgress center
return nil

Function ToExcel(  oProgress , oDlgProgress lEnd, oBrwI, aData ,oSay02 )

LOCAL oExcel   := ExcelObj()
   LOCAL oBook    := oExcel:WorkBooks:Add()
   LOCAL oSheet   := oBook:ActiveSheet
   LOCAL oRange, , nRows :=  Len( aData ), nCols:= Len(aDatos[1]), oCol
   
local nprogress   := 0

       oProgress:SetRange( 0, RecCount() )

        Ut_ResetMeter( oProgress, nProgress )


/* 1st phase here ********/
   While nprogress  <= nRows .AND. ! lEnd
      oRange:Rows( nprogress +2 ):Value  := aData[ nprogress  ]
     // oMeter:Set( n++ )
              oProgress:SetPos(nProgress++)

   End
...
/*2nd phase here  *****
* need to change progress bar dialog message to "Getting graphs from data" */
...
       oSay:SetText(i18n("Getting graphs from data")
               oProgress:SetRange( 0, RecCount() )
                    Ut_ResetMeter( oProgress, nProgress )



   IF lEnd
      MsgAlert( "Report cancel by user", "Excel" )
   Else
      MsgInfo( Len( aData ), "Total animals in these sequence:" )
   EndIf

RETURN Nil


   

I use the same system for index, create dbf and convert into xls,cvs,xlm

Re: Is there a way to change message in MsgMeter?

Posted: Thu May 30, 2019 9:39 am
by ellano
Thanks for your kind responses.

Sorry, but I meant without using a dialog, only the advantages of MsgMeter (if there is a simple way). There is also a oText and oDlg object there, so maybe...

You cannot beat one line of code with at least 20 lines of creating and administrating yourself a dialog :(

Sincerely
Emiliano Llano Díaz

Re: Is there a way to change message in MsgMeter?

Posted: Thu May 30, 2019 9:54 am
by ellano
Ahhhhaaaaaaaa! I answer myself: :mrgreen:

Code: Select all

   FUNCTION ReportToExcel(oBrwI, aData)

       MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
                 ToExcel ( oMeter, oText, oDlg, @lEnd, oBrwI, aData) },;
                 "Sending data to Excel", "Please stand by..." )
    RETURN NIL

    STATIC FUNCTION ToExcel( oMeter, oText, oDlg, lEnd, oBrwI, aData )

       LOCAL oExcel   := ExcelObj()
       LOCAL oBook    := oExcel:WorkBooks:Add()
       LOCAL oSheet   := oBook:ActiveSheet
       LOCAL oRange, n :=1, nRows :=  Len( aData ), nCols:= Len(aDatos[1]), oCol
    ...
    ...
    /* 1st phase here ********/
       While n <= nRows .AND. ! lEnd
          oRange:Rows( n+2 ):Value  := aData[ n ]
          oMeter:Set( n++ )
       End
    ...
    /*2nd phase here  *****
    * need to change progress bar dialog message to "Getting graphs from data" */
    ...
  
   oDlg:cTitle:= "My New oDlg Title goes here!"
   oText:SetText ("The progress bar message is placed here!")

       IF lEnd
          MsgAlert( "Report cancel by user", "Excel" )
       Else
          MsgInfo( Len( aData ), "Total animals in these sequence:" )
       EndIf

    RETURN Nil
The one liner is completely respected and you do not need to administrate a whole dialog.

Emiliano Llano Díaz

Re: Is there a way to change message in MsgMeter?

Posted: Thu May 30, 2019 11:23 am
by Silvio.Falconi
Emiliano,I wouldn't use msgmeter

Re: Is there a way to change message in MsgMeter?

Posted: Thu May 30, 2019 4:15 pm
by ellano
Silvio:

Without being rude, I use both of them and I only see advantages in the 2nd one (unless you clarify the point):

1st method: (at least 5 lines)

Code: Select all

  LOCAL oDlgP, oProg1
  DEFINE DIALOG oDlgP FROM 1, 1 TO 5, 44 ;
      TITLE "Initial configuration"
@ 1, 2 PROGRESS oProg1 SIZE 135, 12
  ACTIVATE DIALOG oDlgP CENTERED NOWAIT ;
        ON INIT (HB_SYMBOL_UNUSED(self), oProg1:SetRange( 0, 100 ))
  oProg1:SetPos( INT(i*100/num_reg ) )  //add to progress bar
  oDlgP:End()                                        //do not forget to close at the end
 
2nd method: (3 lines; very simple to maintain)

Code: Select all

   MsgMeter( { | oMeter, oText, oDlg, lEnd | ;
             AExcel ( oMeter, oText, oDlg, @lEnd, oBrwI, aData, cImages) },;
             "Progress bar message (can change later)...", "Dialog message (can also change later on..." )
  oMeter:nTotal = nRows  // get it from what you want to control
  oMeter:Set( n++ )         // progress bar on a loop

In the same line of thought, we can also implement MsgStop, MsgWait, etc. using the comdlg32.dll loosing all advantages of a simple interface :shock:

Sincerely
Emiliano Llano Díaz