Options

Need help on Table Post Code - Function ValidateCity

jemmyjemmy Member Posts: 247
Folks,

Anyone knows why we need to add
IF PostCodeRec2.NEXT = 1 THEN
in the following code
ValidateCity(VAR City : Text[30];VAR PostCode : Code[20])

IF NOT GUIALLOWED THEN
  EXIT;
IF City <> '' THEN BEGIN
  SearchCity := City;
  PostCodeRec.SETCURRENTKEY("Search City");
  PostCodeRec.SETFILTER("Search City",SearchCity);
  IF NOT PostCodeRec.FIND('-') THEN
    EXIT;
  PostCodeRec2.COPY(PostCodeRec);
  IF PostCodeRec2.NEXT = 1 THEN
    IF FORM.RUNMODAL(FORM::"Post Codes",PostCodeRec,PostCodeRec.Code) <> 

ACTION::LookupOK THEN
      EXIT;
  PostCode := PostCodeRec.Code;
  City := PostCodeRec.City;
END;

Thanks in advance as always,


Jemmy

Comments

  • Options
    AlbertvhAlbertvh Member Posts: 516
    Hi Jemmy

    This code checks if there is more than 1 city in the post code table and if so displays the list of cities with the criteria you have entered.

    Regards

    Albert
  • Options
    jemmyjemmy Member Posts: 247
    I removed the line contained with
    PostCodeCheck.AddressValIsPostCodeCity;
    now it works, but I'm still curious... :?

    Alberth, how about if the city is the last record in the list (means that NEXT = 0)?
  • Options
    AlbertvhAlbertvh Member Posts: 516
    Hi Jemmey
    That is correct
  • Options
    jreynoldsjreynolds Member Posts: 175
    If there are no records or a single record matching the filter criteria then the function exits immediately. If there are multiple records matching the criteria then the user is asked to select the desired one from a list. The obvious way to code this would be to use the COUNT function and test for COUNT > 1. But this is extremely slow on large tables because it must return the exact count and all we are really interested in is if there is more than one record. Thus, NEXT = 1 tells us that another record is found.
  • Options
    jemmyjemmy Member Posts: 247
    Hi JReynolds!

    Then the last record in the list won't open the form modal.
    You have pointed it well. A good trick from the programmer.

    Thanks a lot JReynolds! =D>

    Jemmy
Sign In or Register to comment.