How to jump in code?

nvermanverma Member Posts: 396
edited 2011-11-30 in NAV Three Tier
I am working on Report. If a certain condition is meet I want to jump from here to another point in the code.

Is there like a JUMP command or GOTO command in NAV to make it go from one place in code to another?

Comments

  • ArmondsArmonds Member Posts: 66
    Nop. But there also is no need of them. I still remember from school, that using of GOTO was a bad style even in BASIC :)
  • nvermanverma Member Posts: 396
    at the beginning of the code, I am doing a check, but if the condition of the check is true, I want it to skip bunch of statements and go to another place in the code...so i would need some sorta of command that will let me jump if the condition is true.
  • DenSterDenSter Member Posts: 8,307
    IF <condition = TRUE> THEN BEGIN
      //execute code for when the condition is true
    END ELSE BEGIN
      //execute code for when the condition is not true
    END;
    
    Conversely:
    IF <condition = FALSE> THEN BEGIN
      //execute code for when the condition is not true
    END ELSE BEGIN
      //execute code for when the condition is true
    END;
    
    Or, if you only want to run certain code if the condition is false, and execute the rest regardless of the condition:
    IF <condition = FALSE> THEN BEGIN
      //execute code for when the condition is not true
    END;
    //execute the rest of the code
    
  • nvermanverma Member Posts: 396
    If the "IF (Customer.Birthdate = 0D) THEN" is true, I want it jump from the ****************** to the ================ at the bottom. How can I make that happen.

    This is the code I have.



    IF (Customer.Birthdate = 0D) THEN // If Birthday date is empty, sets Primary Consumer Type to empty
    BEGIN
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::" ";
    END;
    *****************************************************************************************************
    NumberOfDays:= (InputDate - BirthDay); // Gets the difference between the two dates

    PrimaryType := NumberOfDays / 365; // Divides the NumberOfDays with 365 to get total number of year

    CASE PrimaryType OF
    1..17: // If the value is between 1 - 17, sets Primary Consumer Type
    BEGIN // to Child
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::Child;
    END;
    18..64: // If the value is between 18 - 64, sets Primary Consumer Type
    BEGIN // to Adult
    Job."Primary Consumer Type" :=Job."Primary Consumer Type"::Adult;
    END;
    ELSE
    BEGIN // If the value is greater than 65, sets Primary Consumer Type
    // to Senior 65 and over
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::"Senior 65 and over";
    END;
    END;

    IF (Customer.Birthdate = 0D) THEN // If Birthday date is empty, sets Primary Consumer Type to empty
    BEGIN
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::" ";
    END;
    ======================================================================================================
    ProgressDialog.UPDATE(1,Job."No.");
    ProgressDialog.UPDATE(2,"Consumer No.");
    ProgressDialog.UPDATE(3, ROUND(Counter/TotalRecords*10000,1));
  • DenSterDenSter Member Posts: 8,307
    Dude really? You want me to write your code?

    There is no "jump" command, but if you want to execute some code based on a condition, you use an IF statement. Figure it out, try something, see if it works, adjust if it doesn't. A large part of being a developer is the ability to figure out this type of stuff.
  • SavatageSavatage Member Posts: 7,142
    Since you don't know the option yet perhaps you should lose the case statement.

    years = today - birthyear;

    if years = 0 then begin
    do whatever *personally I would error message out forcing a date into this field if it's so important.
    end else begin
    if (years > 0) and (years < 18) then begin
    "Primary Consumer Type" := "Primary Consumer Type"::Child
    end else begin
    if (years > 17) and (years < 65) then begin
    "Primary Consumer Type" := "Primary Consumer Type"::adult
    end else begin
    etc etc etc

    haven't tested:: if years in [1..18] then begin etc etc ( if it works it's better)

    ** sometimes its good to step back after working on something so hard.
    don't overcomplicate. It's not that hard to figure out.
  • DenSterDenSter Member Posts: 8,307
    Yeah I would personally program it differently too, but what the particular question comes down to is the proper use of an IF THEN ELSE construct. He needs to get out of the "I need to jump" mindset, and think about which lines of code need to be executed based on that condition. All he needs is to add an ELSE block in the right position.
  • nvermanverma Member Posts: 396
    Thanks. I got it working. The else worked in that If statement. That was so stupid of me. I dont know why I didnt think of that.
  • DenSterDenSter Member Posts: 8,307
    nverma wrote:
    I got it working
    Awesome :mrgreen:
  • DuikmeesterDuikmeester Member Posts: 308
    Makes me cry sometimes seeing what level of "programmers" are working in Navision. I feel sorry for their customers/employers. ](*,)
  • DenSterDenSter Member Posts: 8,307
    Makes me cry sometimes seeing what level of "programmers" are working in Navision. I feel sorry for their customers/employers. ](*,)
    What, you didn't have a first day/week/year? You came in fully functioning with nothing left to learn?
Sign In or Register to comment.