Edit Check question

4 posts / 0 new
Last post
BillMietelski
Edit Check question

I'm having a little trouble with an edit check and I could use another pair of eyes. :D

If I understood the Dev Guide correctly, the code below runs normally if the condition(s) is/are true, but if they're false the [i]"Address not in neighborhood..."[/i] message would appear.

Did I understand that correctly?
Did I get the syntax right?
Or did I just mess up my Boolean logic? :rolleyes:

BLOCK BIdent

  TYPE

    TArea = ...
   
    TAddrStreet = (Albany       (31) "Albany Ave.",
                   Artesian     (03) "Artesian Ave.",
                   Augusta      (10) "Augusta Blvd.",
                   Bloomingdale (34) "Bloomingdale Ave.",
                   California   (17) "California Ave.",
                   Campbell     (05) "Campbell Ave.",
                   Chicago      (02) "Chicago Ave.",
                   Cortez       (12) "Cortez St.",
                   Crystal      (20) "Crystal St.",
                   Division     (18) "Division St.",
                   Evergreen    (24) "Evergreen Ave.",
                   Fairfield    (15) "Fairfield Ave.",
                   Francisco    (21) "Francisco Ave.",
                   Haddon       (16) "Haddon Ave.",
                   Hirsch       (26) "Hirsch St.",
                   Humboldt     (27) "Humboldt Blvd. (North to Bloomingdale)",
                   Iowa         (06) "Iowa St.",
                   Kedzie       (35) "Kedzie Ave.",
                   Le_Moyne     (28) "Le Moyne St.",
                   Maplewood    (07) "Maplewood Ave.",
                   Mozart       (19) "Mozart St.",
                   North        (30) "North Ave.",
                   Potomac      (22) "Potomac Ave.",
                   Rice         (04) "Rice St.",
                   Richmond     (23) "Richmond St.",
                   Rockwell     (09) "Rockwell St.",
                   Sacramento   (25) "Sacramento Ave. (Chicago to Division)",
                   Talman       (11) "Talman Ave.",
                   Thomas       (14) "Thomas St.",
                   Troy         (33) "Troy St.",
                   Wabansia     (32) "Wabansia Ave.",
                   Walton       (08) "Walton St.",
                   Washtenaw    (13) "Washtenaw Ave.",
                   Western      (01) "Western Ave.",
                   Whipple      (29) "Whipple St.")

    TSingleFamDwell = ...

  FIELDS
    HhArea           ...

    HhAddrNum        "Household Address: Number?"  : 800..3200 {INTEGER ranging from 800 thru 3200}

    HhAddrStreet     "Household Address: Street?" : TAddrStreet

    HhSingleFamDwell ...

    HhAddrUnit       ...

    HhConfirm        ...

  RULES
     {Check valid Humboldt Park street addresses, ie., 800 thru 1800 North, 2400 thru 3200 West}
     (HhAddrStreet IN [Albany,       {Check N-S streets 800..1800}
                       Artesian,
                       California,
                       Campbell,
                       Fairfield,
                       Francisco,
                       Humboldt,
                       Kedzie,
                       Maplewood,
                       Mozart,
                       Richmond,
                       Rockwell,
                       Sacramento,
                       Talman,
                       Troy,
                       Washtenaw,
                       Western,
                       Whipple]
                   AND HhAddrNum >=  800
                   AND HhAddrNum <= 1800)
      OR
     (HhAddrStreet IN [Augusta,      {Check E-W streets 2400..3200}
                       Bloomingdale,
                       Chicago,
                       Cortez,
                       Crystal,
                       Division,
                       Evergreen,
                       Haddon,
                       Hirsch,
                       Iowa,
                       Le_Moyne,
                       North,
                       Potomac,
                       Rice,
                       Thomas,
                       Wabansia,
                       Walton]
                   AND HhAddrNum >= 2400
                   AND HhAddrNum <= 3200)
      "Address not in neighborhood.
       For streets running North-South, addresses must range from 800 to 1800.
       For streets running East-West, addresses must range from 2400 to 3200."

     ...
    
     HhAddrNum.KEEP
     HhAddrStreet.KEEP
    
     ...
    
ENDBLOCK

fwensing
fwensing's picture
Yes

Hi Bill

Yes you are right with your interpretation.

As for your Code I would recommend that you add the word CHECK or SIGNAL before each edit/check definition. That way you will know (when you examine the source code) which type of edit it was intended to be.

Depending on the type of check you wish to apply you might find it easier to write multiple edits within IF/THEN/ELSE constructs, rather than one only. For example:

{Check valid Humboldt Park street addresses, ie., 800 thru 1800 North, 2400 thru 3200 West}
IF (HhAddrStreet IN [Albany,       {Check N-S streets 800..1800}
                   Artesian,
                   California,
                   Campbell,
                   Fairfield,
                   Francisco,
                   Humboldt,
                   Kedzie,
                   Maplewood,
                   Mozart,
                   Richmond,
                   Rockwell,
                   Sacramento,
                   Talman,
                   Troy,
                   Washtenaw,
                   Western,
                   Whipple])
                   "For streets running North-South"
THEN
    CHECK
    (HhAddrNum >=  800) AND (HhAddrNum <= 1800)
    "addresses must be in the range from 800 to 1800."
ELSEIF (HhAddrStreet IN [Augusta,      {Check E-W streets 2400..3200}
                       Bloomingdale,
                       Chicago,
                       Cortez,
                       Crystal,
                       Division,
                       Evergreen,
                       Haddon,
                       Hirsch,
                       Iowa,
                       Le_Moyne,
                       North,
                       Potomac,
                       Rice,
                       Thomas,
                       Wabansia,
                       Walton])
                       "For streets running East-West"
THEN
    CHECK
    (HhAddrNum >= 2400) AND (HhAddrNum <= 3200)
      "addresses must range from 2400 to 3200."
ENDIF

Notice how the additional text which is attached to the IF condition also adds to the edit message.

I don't know why you have the two KEEPs in your code. I would have thought that you would ask the two fields HhAddrNum and HhAddrStreet first. You cannot apply an edit check against two fields that you cannot change. One or both of them must be ASK type fields otherwise the edit check cannot be resolved by the operator.

Good luck

Fred :cool:

BillMietelski
Thanks again, Fred ... and one follow-up question.

As for the KEEPs, that's interesting...

This block is one of the first Blaise blocks that I ever wrote. At the time I was struggling with getting my [url=http://www.blaise.com/forum/thread/100]primary key stuff to work[/url]. (HhAddrNum & HhAddrStreet are part of the primary key.)

The KEEPs are leftovers from that early code. The interesting thing is that when I run the survey, the HhAddrNum and HhAddrStreet fields [b][i]are asked[/i] [/b]even though the KEEP code is there. I don't know what that's all about - back when I was playing with this code the first time around Blaise would execute some code one way, but then as soon as I added the PRIMARY keyword the code would act differently even though the rest of the code remained unchanged. I'll try and figure that out later.

As for the syntax of my edit check - I must've "borrowed" that from somewhere because it's definitely not the style that I would normally use. I prefer your syntax as it's much closer to the syntax I'm familiar with in most of the other programming languages I know.

Now the follow-up question - here's the latest code I'm trying:

BLOCK
{code removed to save space...}
  RULES
     HhArea
     HhAddrNum
     HhAddrStreet

     {Check valid Humboldt Park street addresses, ie., 800 thru 1800 North, 2400 thru 3200 West}
     IF (HhAddrStreet IN [Albany,       {Check N-S streets 800..1800}
                          Artesian,
                          California,
                          Campbell,
                          Fairfield,
                          Francisco,
                          Humboldt,
                          Kedzie,
                          Maplewood,
                          Mozart,
                          Richmond,
                          Rockwell,
                          Sacramento,
                          Talman,
                          Troy,
                          Washtenaw,
                          Western,
                          Whipple])
                          "For streets running North-South"
     THEN
       CHECK
        (HhAddrNum >=  800) AND (HhAddrNum <= 1800)
        "addresses must be in the range from 800 to 1800."
     ELSEIF (HhAddrStreet IN [Augusta,      {Check E-W streets 2400..3200}
                              Bloomingdale,
                              Chicago,
                              Cortez,
                              Crystal,
                              Division,
                              Evergreen,
                              Haddon,
                              Hirsch,
                              Iowa,
                              Le_Moyne,
                              North,
                              Potomac,
                              Rice,
                              Thomas,
                              Wabansia,
                              Walton])
                              "For streets running East-West"
     THEN
       CHECK
        (HhAddrNum >= 2400) AND (HhAddrNum <= 3200)
        "addresses must range from 2400 to 3200."
     ENDIF

     HhSingleFamDwell
     HhAddrUnit
     IF HhSingleFamDwell = EMPTY THEN
       HhAddrUnit := '   '
     ELSEIF HhSingleFamDwell = Yes THEN
       HhAddrUnit := '000'
     ENDIF
     HhConfirm

ENDBLOCK

The code runs fine, except the error message doesn't appear until after the HhConfirm field is asked & answered. I would much rather the message appear immediately after HhAddrStreet is filled in instead of allowing the user to input three more fields before being alerted to a problem in an earlier field.

What's the best way to get the error message to pop up right away, instead of at the end of the block?

fwensing
fwensing's picture
Watch your primary key

Hi Bill

I presume that you have set all those Hh fields to be in the Primary key. You need to realise that the record does not 'exist' until all the elements of the key have been entered. Only then can the rules work properly on your record. That is the reason for the apparent delay.

I would not put those fields into the primary key. The main reason is that address type fields are susceptible to change because of spelling errors, corrections etc. Not good. You need a stable Primary key even if you just come up with a sequential numbering system. Of course you could put the address fields into a secondary key if you need it for searching or processing reasons.

You need to have some kind of case management system to manage the records, assign unique IDs and start up the interview. The things you are doing with the address fields here are probably best handled in the case management system. If you don't have one you can build a rudimentary one in Maniplus. Check my paper on the subject from IBUC 2009.

Cheers

Fred:cool:

Log in or register to post comments