Page 3 of 4

Re: Set Date and Time to Operacional System

Posted: Tue Jan 24, 2012 6:15 pm
by Rossine
Hello Pablo,

In compiling this latest version with harbour in this error occurs in executing:

Error BASE/1132 Erro de limite: acesso de array

Called from MAIN(79)

To solve the problem I changed this line and now is ok:

# define MYPATH GetStartUpFolder () + "\"

Thank you,

Rossine.

Set Date and Time to Operacional System

Posted: Tue Jan 24, 2012 7:58 pm
by Pablo César
Strange Rossine, for me here MYPATH ends with "\", so do not need to add a backslash.
Error BASE/1132 Erro de limite: acesso de array

Called from MAIN(79)
In Main, which is Acerta.prg at line 79 is:

nSt1 := WidthString(aLng[3]+PCATUAL)+10

So it´s means that could not have read the languages file (Portuguese.lng and English.lng).

Do you compile with Minigui Extended ? Thru Build.bat, which is in the package ?

Re: Set Date and Time to Operacional System

Posted: Tue Jan 24, 2012 9:08 pm
by Pablo César
I think I know the reason.

In MiniGUI (HMG Extended Edition), GetStartUpFolder() is:

#xtranslate GetStartUpFolder () => cFilePath( GetExeFilename() )

which is also translated to:

#translate Application.ExeName => GetExeFileName()

What it´s means that GetStartUpFolder() is the same that cFilePath( Application.ExeName )

And in HMG it´s:
- According Changelog of HMG 3.0.40, is new function taken by C:\hmg.3.0.40\SOURCE\h_controlmisc.prg:

Code: Select all

Function GetStartUpFolder()
Local StartUpFolder := GetProgramFileName()

Return Left ( StartUpFolder , Rat ( '\' , StartUpFolder ) - 1 )
Here (in last line of this function) is taking off the last slash.

So for compatibility, in case of using both tools can be placed:

# define MYPATH GetStartUpFolder() + If(Right(GetStartUpFolder(),1)="\","","\")

or

# define MYPATH Left ( GetProgramFileName() , Rat ( '\' , GetProgramFileName() ) - 1 )

Re: Set Date and Time to Operacional System

Posted: Wed Jun 13, 2012 10:58 pm
by brain
Good Day! I'M looking for an AddMonth functions. Is there any of can share?
For Example I entered 01/31/2012 + 1 month = 02/29/2012.
Tnx..

Re: Set Date and Time to Operacional System

Posted: Thu Jun 14, 2012 2:01 am
by IMATECH

Code: Select all


*----------------------------------------------------------------*
* FUNCTION F_RM_Push_Date( nDate, iYear, iMonth, iDay)
*
* Sample for Use:
* ? F_Push_Date( DATE(), 0, 0, 1 ) => Result Date() + 1 Day
* ? F_Push_Date( DATE(), 0, 1, 0 ) => Result Date() + 1 Month
* ? F_Push_Date( DATE(), 1, 0, 0 ) => Result Date() + 1 Year
* ? F_Push_Date( DATE(), 1, 1, 1 ) => Result Date() + 1 Day + 1 Month + 1 Year
*
* Increase/Decrease Date in: Days, Months or Years
*
* Author: Ronaldo M. chacalgo@gmail.com
*
* Creation Date: 06/13/2012
* Last Update on: 06/20/2012 -> Any bug/updates: please send to Author
*----------------------------------------------------------------*
FUNCTION F_RM_Push_Date( nDate, iYear, iMonth, iDay)
  LOCAL nYear := Year(nDate)
  LOCAL nMonth := Month(nDate)
  LOCAL nDay := Day(nDate)
  LOCAL aDay := { 31, IIF( ISLEAPYEAR( nDate ), 29, 28 ), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  LOCAL nAux := 0
  LOCAL l_Last_Day := ( nDay >= aDay[ nMonth ])

  IF iYear # 0
    nYear += iYear
  ENDIF

  IF iMonth # 0
    nMonth += iMonth
    WHILE nMonth > 12
      nYear++
      nMonth += -12
    ENDDO
    WHILE nMonth < 0
      nYear++
      nMonth +=  12
    ENDDO
    IF nMonth == 0
      nMonth := 12
      nYear--
    ENDIF
  ENDIF

  nDay := IIF( l_Last_Day, aDay[ nMonth ], IIF( nDay > aDay[ nMonth ], aDay[ nMonth ], nDay ) )

  IF nMonth == 2
    nAux := IIF( ISLEAPYEAR( STOD( STRZERO( nYear, 4 ) + '0101' ) ), 29, 28)
    nDay := IIF( l_Last_Day, nAux, IIF( nDay > 28, nAux, nDay ) )
  ENDIF

  nDate := STOD( STRZERO( nYear, 4 ) + STRZERO( nMonth, 2 ) + STRZERO( nDay, 2) )

  nDate += iDay

RETURN( nDate )


Re: Set Date and Time to Operacional System

Posted: Thu Jun 14, 2012 2:12 am
by Rathinagiri
Thanks a lot. It is very much useful.

Re: Set Date and Time to Operacional System

Posted: Thu Jun 14, 2012 2:55 pm
by apais

Code: Select all

//---------------------------------------------------------------------------//
FUNCTION BOM(dDate)  // Begin of Month
IF dDate = NIL
   dDate := DATE()
ENDIF
RETURN (dDate-DAY(dDate)+1)
//---------------------------------------------------------------------------//
FUNCTION EOM(dDate) // End of Month
IF dDate = NIL
   dDate := DATE()
ENDIF
dDate += ( 45 - day( dDate ) )
return dDate - day( dDate )
//---------------------------------------------------------------------------//
FUNCTION ADDMONTH(dDate,nHowMany) // Add or substract months
LOCAL nToday
IF VALTYPE(dDate) <> 'D'
   dDate := DATE()
ENDIF
IF VALTYPE(nHowMany) <> "N"
   nHowMany := 1
ENDIF
nToday := DAY(dDate)
DO WHILE nHowMany <> 0
   IF nHowMany > 0
      dDate := EOM(dDate)+1
      nHowMany--
   ELSE
      dDate := BOM(BOM(dDate)-1)
      nHowMany++
   ENDIF
ENDDO
RETURN(dDate-1+nToday)
//---------------------------------------------------------------------------//
HTH
Angel

Re: Set Date and Time to Operacional System

Posted: Sun Jun 17, 2012 2:04 am
by brain
Tnx to Chacal.GO and apais for sharing their date functions. I'll gonna use this for my future projects. God Bless to all. Viva HMG...

Re: Set Date and Time to Operacional System

Posted: Mon Jun 18, 2012 5:59 am
by brain
Good Day Chacal.GO. I have a bug encountered to your function here it is.
Try F_Push_Date( CTOD('12/31/2012'), 0, 1, 0 ) => Result 01/31/2014 instead of 01/31/2013
Hope to resolve this problem. Tnx.

Re: Set Date and Time to Operacional System

Posted: Mon Jun 18, 2012 6:07 am
by brain
Good Day apais. I have a bug encountered to your function here it is.
Try AddMonth( CTOD('12/31/2012'), 4 ) => Result 05/1/2013 instead of 04/30/2013
Hope to resolve this problem. Tnx.