John Blue
John Blue

Reputation: 51

Set date in single line edit on opening

I'm using PowerBuilder 10.5 and I have two single line edit (SLE) fields - sle_date1 and sle_date2 on my window.

What I need is for those two fields to be filled once I open my program. sle_date2 has to have the value of today (for example - 09.07.13), and sle_date1 has to have the value of (sle_date2-30 days) (example 09.06.13).

So, as I said, once I open my programs both fields would be filled immediately with values of today's date and the date of a month before.

How could I do that? Any advice just to get me going?

Upvotes: 2

Views: 2702

Answers (2)

Seki
Seki

Reputation: 11465

  • You can add some code to populate the edits in the open() event of your window
  • with a given date that can be today(), you can compute a new date plus / minus a number of days with RelativeDate()

The following code just answers your question (though it could be better to use some editmask controls instead of singlelineedit as it would ease the handle of user's input):

date ld_now, ld_previousmonth
string ls_datefmt

ls_datefmt = "dd.mm.yy"
ld_now = today()
sle_1.text = string(ld_now, ls_datefmt)
ld_previousmonth= RelativeDate(ld_now, -30)
sle_2.text = string(ld_previousmonth, ls_datefmt)

It shows 09.07.13 and 09.06.13 at this time.

Upvotes: 1

DARKinVADER
DARKinVADER

Reputation: 640

first of all you need to open your window. You can to this with put this code in your application open event (let suppose that your window is w_main):

open(w_main)

After that in put this code in your window's open event:

sle_date1.text  = string(today())
sle_date2.text  = string(RelativeDate(Today(), -30))

I think this solves your problem. Here is a little help for RelativeDate:

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.pocketbuilder_2.0.pkpsref/html/pkpsref/pkpsref662.htm

Best Regards Gábor

Upvotes: 1

Related Questions