Set Date and Time to Operacional System

HMG Samples and Enhancements

Moderator: Rathinagiri

Rossine
Posts: 87
Joined: Thu Jun 30, 2011 10:04 pm

Re: Set Date and Time to Operacional System

Post 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.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Set Date and Time to Operacional System

Post 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 ?
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

Re: Set Date and Time to Operacional System

Post 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 )
Last edited by Pablo César on Tue Jan 24, 2012 9:18 pm, edited 2 times in total.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
brain
Posts: 26
Joined: Tue Aug 02, 2011 5:01 pm

Re: Set Date and Time to Operacional System

Post 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..
User avatar
IMATECH
Posts: 188
Joined: Sun May 27, 2012 9:33 pm
Location: Brazil: Goiânia-GO.

Re: Set Date and Time to Operacional System

Post 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 )

Last edited by IMATECH on Wed Jun 20, 2012 3:16 am, edited 11 times in total.
M., Ronaldo

By: IMATECH

Imation Tecnologia
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Set Date and Time to Operacional System

Post by Rathinagiri »

Thanks a lot. It is very much useful.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: Set Date and Time to Operacional System

Post 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
Angel Pais
Web Apps consultant/architect/developer.
User avatar
brain
Posts: 26
Joined: Tue Aug 02, 2011 5:01 pm

Re: Set Date and Time to Operacional System

Post 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...
User avatar
brain
Posts: 26
Joined: Tue Aug 02, 2011 5:01 pm

Re: Set Date and Time to Operacional System

Post 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.
User avatar
brain
Posts: 26
Joined: Tue Aug 02, 2011 5:01 pm

Re: Set Date and Time to Operacional System

Post 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.
Post Reply