MsgBar Time in AM/PM Format

MsgBar Time in AM/PM Format

Postby anserkk » Mon Sep 01, 2008 10:47 am

Friends,

1) Is it poosible to show the time in MsgBar in AM/PM Format. Right now I understand that it is possible only in the 24 hr format.

Code: Select all  Expand view  RUN
For eg : SET MESSAGE OF oWnd TO "My Company name" DATE CLOCK(AMPM)


2) Any working sample code showing how to insert a new msg item at a desired position in MsgBar.

3) I would also like to know how to change the Text/Prompt of an already added msg item

Regards

Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby Antonio Linares » Mon Sep 01, 2008 11:15 pm

Anser,

For 2) and 3) please review fwh\samples\TestMsg3.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Mon Sep 01, 2008 11:17 pm

1)

Do we have a function AMPM( cTime ) at hand ? Thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Mon Sep 01, 2008 11:24 pm

This one ?
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

   MsgInfo( AMPM( "17:12:00" ) )

return nil

function AMPM( cTime )

   local nHour

   if ( nHour := Val( SubStr( cTime, 1, 2 ) ) ) > 11
      cTime = PadL( AllTrim( Str( nHour - 12 ) ), 2, "0" ) + SubStr( cTime, 3 ) + " PM"
   else
      cTime += " AM"   
   endif

return cTime
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby anserkk » Tue Sep 02, 2008 6:14 am

Thank you Mr.Antonio

1) Is it poosible to show the time in MsgBar in AM/PM Format. Right now I understand that it is possible only in the 24 hr format.

Regarding the AM/PM format in Clock on MsgBar, I included a modified \C:\FWH\source\classes\MsgBar.Prg version on my Application prg's and added the modified MsgBar.PRG in my .rmk file. It is working fine

Code: Select all  Expand view  RUN
METHOD ClockOn() CLASS TMsgBar

   local cTime := Time()

   if ::oClock == nil
      // keep the ':=' below for XBase++ compatibility
      ::oClock := TMsgItem():New( Self, cTime, ::GetWidth( cTime ) + 18,,,, .t.,;
                                 { || WinExec( "Control date/time" ) } )
      ::oClock:lTimer = .t.
      [b]::oClock:bMsg   = { || AMPM(Time()) }[/b]
   endif
   ::CheckTimer()

return nil

*---------------------------------------*
function AMPM( cTime )
*---------------------------------------*
   local nHour

   if ( nHour := Val( SubStr( cTime, 1, 2 ) ) ) > 11
      cTime = PadL( AllTrim( Str( nHour - 12 ) ), 2, "0" ) + SubStr( cTime, 3 ) + " PM"
   else
      cTime += " AM"   
   endif

return cTime


Would be better if you could include this option in the next version. So that the prgrammer can pass a parameter AMPM to display time in AMPM format in the MsgBar

3) I would also like to know how to change the Text/Prompt of an already added msg item

fwh\samples\TestMsg3.prg helped me to solve

Code: Select all  Expand view  RUN
   if oWnd:oMsgBar:GetItem() < 3
      oItem := TMsgItem():New( oWnd:oMsgBar, cDispFnStr,110, ,"R*/BG",;
                      ,.t., ,,, "Active Financial Year" )
        oItem:bAction:={ || SelYear()}
    else
       [b]oWnd:oMsgBar:aItem[3]:cMsg:=cDispFnStr[/b]
    Endif
                         
                                 OR

DEFINE MSGITEM cDispFnStr OF oWndEdit:oMsgBar SIZE 30 COLOR "R+/W" TOOLTIP "Active Financial Year" ACTION SelYear()



2) Any working sample code showing how to insert a new msg item at a desired position in MsgBar.

Unfortunately I could not find any sample to Insert a MsgItem at a desired position.
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby anserkk » Tue Sep 02, 2008 6:41 am

Dear Mr.Antonio

A small bug in the Function AMPM

Instead of 12:05 PM it is showing 00:05 PM

Screen Snapshot

Image

Regards

Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby anserkk » Tue Sep 02, 2008 7:31 am

This is working fine. I don't know whether this is the best way.

f
Code: Select all  Expand view  RUN
unction AMPM( cTime )

   local nHour

   if ( nHour := Val( SubStr( cTime, 1, 2 ) ) ) > 11
        if nHour == 12
        cTime = PadL( AllTrim( Str( nHour) ), 2, "0" ) + SubStr( cTime, 3 ) + " PM"
        else
      cTime = PadL( AllTrim( Str( nHour - 12 ) ), 2, "0" ) + SubStr( cTime, 3 ) + " PM"
      Endif
   else
      cTime += " AM"   
   endif

return cTime
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby Antonio Linares » Tue Sep 02, 2008 8:22 am

3) From fwh\samples\TestMsg3.prg
Code: Select all  Expand view  RUN
             oItem := TMsgItem():New( oWnd:oMsgBar, "Hello", 60, oFont,"R*/BG",;
                      ,.t., {|| oItem:SetText( If( oItem:cMsg == "Hello", "Bye", "Hello" ) ) },,, "Test" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42125
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby anserkk » Tue Sep 02, 2008 9:07 am

Dear Mr.Antonio,

I have already created a new msg Item, but I have NOT yet succeded in inserting the new msg item as the first item or at the desired position with the following code

I need different msg items to be displayed in the MsbBar

For Eg: Active Financial year
User Name etc.

Code: Select all  Expand view  RUN
cDispFnStr:="Fn.Year : 2008-2009"
   oItem := TMsgItem():New( oWnd:oMsgBar, cDispFnStr,110, ,"R*/BG",;
                      ,.t., ,,, "Active Financial Year" )
        oItem:bAction:={ || SelYear()}
        oWnd:oMsgBar:insItem( oItem, 1 )


The above code is not inserting the Fn.Year string as the first MsgItem. Instead of that it is appearing as the last item in the MsgBar. Likewise I need to add a MsgItem UserName next to the Msg Item "Fn. Year 2008-2009". I don't know where I have went wrong.

Screen Snapshot

Image

Regards

Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby nageswaragunupudi » Tue Sep 02, 2008 9:20 am

AMPM function is provided by both Harbour and xHarbour. We can use the builin function.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10660
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby nageswaragunupudi » Tue Sep 02, 2008 9:34 am

May be the following code is simple and does what you want and present the msgitems in the order you like to
Code: Select all  Expand view  RUN
#include 'fivewin.ch'

function Main()

   LOCAL oWnd

   DEFINE WINDOW oWnd

   SET MESSAGE OF oWnd TO "" NOINSET 2007 // TIME

   DEFINE MSGITEM OF oWnd:oMsgBar PROMPT 'CompanyName' SIZE 100
   DEFINE MSGITEM OF oWnd:oMsgBar PROMPT wNetGetUser() SIZE 100
   DEFINE MSGITEM OF oWnd:oMsgBar PROMPT "FinYear : 2008-09" SIZE 100
   oWnd:oMsgBar:ClockOn()
   oWnd:oMsgBar:oClock:bMsg   := { || AMPM( Time() ) }
   oWnd:oMsgBar:oClock:nWidth += 20

   ACTIVATE WINDOW oWnd

return nil


The msgitems are shown in the order in which we write them. For that reason, I invoked clock at the end.

Mr Antonio gave us the FiveWin libraries with great flexibilty of usage. We can achieve manythings using just the codeblocks. We do not need to modify the FiveWin source code to a large extent. In any case, where we can get what we want without modifying the library, it is highly desirable not to modify the library. If we modify. we can not keep pace with updates of FWH libraries, which are updated every month.

Also before we attempt to modify FW libraries let us make doubly sure that there is no way of achieving what we want without modifying the library iteself
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10660
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby anserkk » Tue Sep 02, 2008 10:24 am

Thankyou Mr.Nageshwara Rao

What u said is right. I am just a beginner in FWH and I need inputs from experienced people like you and other fellow members of this forum.

As you said, to avoid complications, I should add different MsgItems in their respective orders initially itself.

My application initially displays a Login Screen, after successfull login it will show another dialogue with a list box to choose the financial year to be worked/loaded. So after each successful events I add new msg Items. I think I should re-arrange the process of updating MsgItems

Regards

Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby nageswaragunupudi » Tue Sep 02, 2008 10:44 am

We can create all msgitems at the outset and refersh value of fin year after fin year is selected ( if you are selecting fin year after displaying the main window).

Personally I do not show Time on msg bar because anyway windows shows time on the taskbar. Showing time again in our program is superflous and does not serve any additional benefit to the user. Anyway the choice is yours.

Same sample as above to update the fin year after user enters the fin year:
Code: Select all  Expand view  RUN
#include 'fivewin.ch'

function Main()

   local oWnd, miFinYear, cFinYear := Space( 7 )

   DEFINE WINDOW oWnd

   SET MESSAGE OF oWnd TO "" NOINSET 2007 // TIME

   DEFINE MSGITEM OF oWnd:oMsgBar PROMPT 'CompanyName' SIZE 100
   DEFINE MSGITEM OF oWnd:oMsgBar PROMPT wNetGetUser() SIZE 100
   DEFINE MSGITEM miFinYear OF oWnd:oMsgBar ;
      PROMPT "FinYe : " + cFinYear SIZE 100
   miFinYear:bMsg := { || "FinYr : " + cFinYear }

   // if you think it is necessary to show clock
   oWnd:oMsgBar:ClockOn()
   oWnd:oMsgBar:oClock:bMsg   := { || AMPM( Time() ) }
   oWnd:oMsgBar:oClock:nWidth += 20

   ACTIVATE WINDOW oWnd ;
      ON INIT ( cFinYear := SelFinYear(), miFinYear:Refresh() )

return nil

static func SelFinYear()

   local cYear  := Space( 7 ), n
   local aYears := { '2005-06', ;
                     '2006-07', ;
                     '2007-08', ;
                     '2008-09'  }

   n  := MsgList( aYears )
   cyear   := aYears[ n ]

   // you will have ur own code instead of this

return cYear
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10660
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby anserkk » Tue Sep 02, 2008 11:21 am

Thank you Mr.NageswaraRao,

I reviewing my code and making the necessary changes based on your inputs.

Regards
Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 32 guests