ScreenIO date processing

Discussion about software products provided for the BR community and created by its members. This includes (but is not limited to): MyEdit, File IO, Screen IO, FNSnap, and Utilities written in other languages for use with Business Rules.

Moderators: Susan Smith, admin, Gabriel

Susan Smith
Posts: 654
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

ScreenIO date processing

Postby Susan Smith » Fri Apr 03, 2015 7:18 pm

Hi all (or Gabriel in particular, if he sees this),

In theory, with the addition of the DATE conversion feature in ScreenIO designer, is there a reason to have custom date validation routines beyond this? And if not, would DATE(M/D/CY) allow the entry of a blank (zero) date, setting the julian date value as 0?

I must be doing something wrong, but I have several date fields on one screen. One of them is required, and the other two are optional. I know that using DATE(M/D/CY) in the conversion field will prohibit BAD non-zero dates, but what about blank dates?

It's not acting as I expect. It might be ScreenIO. It might be just the way that DATE() works. Or it might be me. I'm looking into this because I'm finding that as I go back into some screens and run them, it allows me to enter a zero date initially, but once I successfully entered a valid non-zero date into the field, I can't go back and clear it out by entering zeros (or using Field/+ key. What happens is that ScreenIO puts back the prior date back in. But it let me get through the field the first time, leaving it blank. So I'm a little confused as to how it's SUPPOSED to work.

Clear as mud?

Thanks!

-- Susan

Gabriel
Posts: 354
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Re: ScreenIO date processing

Postby Gabriel » Sat Apr 04, 2015 10:43 am

Susan,

ScreenIO allows a zero date initially because initially your code is setting it (or in this specific case, your code is not setting it and everything defaults to 0). Validation Routines (even automatic ones like DATE) don't run until the user changes the value.

However, the good news is you can accomplish what you're trying to do with a simple validate function. I've written one and included it in this post.

Just
1) download it and put it in your "function" folder.
2) Then select it as the validate function for date fields that you want to allow 0 in.
3) Finally, put the date mask in both your Conversion and Userdata fields.

ValidateDatesZero.gif
ValidateDatesZero.gif (27.78 KiB) Viewed 507 times


If you look at the source code below, you can see how it works.

The first thing I do is have a comment explaining how to use the function. Thats pretty important because it can be easy to forget when months or years go by and I need to use the functionality for another customer in another application.

The function is simple - it checks to see if the date entered is zero. If its zero, then it temporarily clears the Conversion spec suspending ScreenIO's automatic date processing. If the entered data is anything other then zero, it sets the Conversion spec back, enabling normal ScreenIO automatic date processing.

Gabriel


Code: Select all

 ! function\validatedateallowzero.brs
 ! Created on 09/07/2013
 !
 ! fnValidateDateAllowZero - This Function is for fields with Dates
 !  where 0 is a valid date. If 0 is detected, normal date processing
 !  is suspended. If 0 is not detected, normal date processing proceeds
 !  as usual. Put your Date spec in both the Conversion and UserData
 !  fields, in order for this to work properly.
 !
 !
 def fnValidateDateAllowZero(;___,Number)
    if trim$(FieldText$)(1:1)="+" or trim$(FieldText$)(1:1)="-" then
       CnvrtIn$(ControlIndex)=UserData$(ControlIndex)
    else
       let Number=99999999
       let Number=val(fieldtext$) conv Ignore
       if Number=0 then
          CnvrtIn$(ControlIndex)=""
       else
          CnvrtIn$(ControlIndex)=UserData$(ControlIndex)
       end if
    end if
    let fnValidateDateAllowZero=1
 fnend
Attachments
validatedateallowzero.brs
(865 Bytes) Downloaded 13 times

Susan Smith
Posts: 654
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Re: ScreenIO date processing

Postby Susan Smith » Sat Apr 04, 2015 12:08 pm

Brilliant! I would have never thought of this. Thank you! And thanks too for the reminder about how the validation functions work. I often (like now) forget that they fire only if something changes. I assume that they fire every time the user goes through that field with an "enter" key. That explains a lot. There is a date on my screen that is used in a calculation for another field. But that date is defaulted to something in the init function when the screen opens. So when my user was "clicking through" that defaulted date without changing it, the calculation for the other field was not firing. Now I know why.

What is the purpose of having the DATE() function in the USERDATA field? Is it so that when you temporarily remove DATE() it from the CONVERSION field, you know what is supposed to be replaced there afterward?

-- Susan

Gabriel
Posts: 354
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Re: ScreenIO date processing

Postby Gabriel » Sat Apr 04, 2015 12:19 pm

Yes, if you have a field used as part of a calculation for another field, and you initialize the field to something, then you need to run your calculation when you initialize the date. You'll also want to run your calculation in the validate field so that your calculation reruns when the user changes the field.

Yes, the reason you need to put the conversion spec in UserData as well as Conversion, is just for this particular validate function, so that it knows what to set back into Conversion when it needs to reenable the automatic date processing.

There's probably a better way to write the validation that doesn't require you to do this, but I just did the quickest thing I could think of to make it work, back when I originally wrote it.

I use the UserData field a lot in my custom functions, to make it so the same function works for any field I want to put it on. It really helps to have reusable custom functions.


Another one that my customers really love, is the ability to put a "Print List" button on any screen that has a listview, and it uses Georges function to print the listview directly to an RTF file and open it in Microsoft Word and Print it if they want.

Its so easy to do. All I have to do is:

1) Add a button
2) Select "PrintListview" for my buttons click event
3) Type the Listviews ControlName in the Buttons UserData field

the cool thing about Georges function is it prints the list exactly the way it is at the time of the click. If they sort it or filter it, it prints just the rows that still appear on the list. This makes it so that even a simple listview screen that I can throw together in 10 minutes, is endlessly useful for my customers.

Now if I could just figure out how to charge for software by what its worth, instead of by how hard it was to make, i'd be doing great. Prior to ScreenIO, a program like that, with a filterable sortable list and print functionality, would have taken 6 to 10 hours to write for a seasoned developer. So I should be doing it in 10 minutes and charging 8 hours .. but I just can't bring myself to do that..

Gabriel

Susan Smith
Posts: 654
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Re: ScreenIO date processing

Postby Susan Smith » Sat Apr 04, 2015 12:38 pm

I haven't made too much use of Userdata yet. sometime, when you have a chance, I would love to see an example of how you use it to make functions more universal. I am better at that than I used to be when I first started with ScreenIO, but I still have a long way to go with WAY too many custom functions. And I haven't used the "userdata" field to streamline it.

-- Susan

Gabriel
Posts: 354
Joined: Sun Aug 10, 2008 7:37 am
Location: Arlington, TX
Contact:

Re: ScreenIO date processing

Postby Gabriel » Sat Apr 04, 2015 12:42 pm

Check out the ValidateDateAllowZero function that I sent in the beginning of this post, for an example of using UserData to make a function more reusable. :) There are a lot of other ways to use it as well, so I agree, more examples would probably help.

I just write a function and then I realize that, there's only one little part of it that is customized to this specific situation, why not stick that little part of it in UserData instead.

UserData was added originally because of a request from you.. so you're the inventor of "UserData". :)

Gabriel

Susan Smith
Posts: 654
Joined: Sun Aug 10, 2008 4:24 am
Location: Southern California

Re: ScreenIO date processing

Postby Susan Smith » Sat Apr 04, 2015 1:26 pm

Ha ha! Yes, I remember requesting it. I wish I remembered what I used it for. I think I'll load my screens into the Data Crawler so I can find those spots again. I have so many screens now, and they were written over such a long time and so many generations of ScreenIO, that I forget! And now that you have added so much more functionality to the product, it's a little embarrassing to see those early custom functions that I wrote before there were better ways to do things. But that happens in plain ol' BR too. I should find more ways to use Userdata. And the reminder comes at just the perfect time.

-- Susan


Return to “3rd Party Software from the BR Community”

Who is online

Users browsing this forum: No registered users and 1 guest

cron