On Aug 10, 2006, at 12:14 PM, Robert Poland wrote:

Oops, forgot the subjecy

Subjecy  ?? Typo I guess. ;-)

On Aug 10, 2006, at 11:51 AM, Robert Poland wrote:

Hi,

I have this test project;
The intent is to take a date entered in the editfield and test that it is a Saturday. If it is then enter the long date in the editfield. If it's nat a Saturday then do a msgbox and update the entered date to the full shortdate.

The ultimate goal is to be able to enter the date and when going to the next field validate the date entered.

I has two editfields and one pushbutton;
the following code if entered in the lostfocus field won't run. I entered in the MouseDown of the Pushbutton it works fine.

Why wouldn't you use the action event of the pushbutton?

  Dim d As date

You need to instantiate the date object.

Dim d as New Date

  Dim s,t As string= ""
  Dim b As boolean

  s = editfield1.text
  b=parsedate(s,d)
  t=d.longdate

  If InStr(t, "Saturday") = 0 then
    MsgBox "That is not a Saturday"
    t=d.shortdate // strip day off bad day
    editfield1.text=t // update display to complete shortdate
  else
    // was a Sat., update display to a longdate
    t=d.longdate
    editfield1.text=t
  end

Any clue what's wrong?

If you add the New Date to the dim d statement it will sort of work in the lost focus event.

Also why are you bothering with strings at all. The date object has a property called DayOfWeek that you can test directly.

I would also not put it in the LostFocus event of EF1 but put it in the GotFocus event of EF2.

Here's my code for EditField2's GotFocus event:

  Dim d As New date// Add NEW
  Dim b As boolean

  b=parsedate(editfield1.text,d)

// Check the parsed date for incorrect entry. That's why it's a Boolean. :)

  If b <> True Then
    MsgBox "Invalid Date format!"
    EditField1.SetFocus//Go back to fix date
    Return// Abort rest of event
  end if


  If d.DayOfWeek <> 7 Then // 7 is Saturday
    MsgBox "That is not a Saturday"
    editfield1.text=d.ShortDate
  Else
    // was a Sat., update display to a longdate
    editfield1.text=d.LongDate
  End If

HTH

Terry

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to