Forum Discussion

kimmatsumoto's avatar
kimmatsumoto
Contributor
6 years ago

code not stepping into the "case" statement

Hello,

 

I'm using similar code in my project without any issues but the following code is not working as expected:

function GetCBOProfileSabreProfileID(varsp1);
var
page, obj;
begin
page := Sys.Browser('*').Page(EnvironmentSettings2.GetServerURL + '*');
obj := GetNativeWebObject(page, 'id', 'fieldAdditionalInfoSabreProfileID');
obj.ScrollIntoView(false);
Delay(1000);
obj.innertext;
obj := obj.innertext;
CBOSabreProfileIDInput := obj;

//Assign var1 for the persistent variable
case varsp1 of
'CBOSabreID0':
begin
ProjectSuite.Variables.CBOSabreID0 := CBOSabreProfileIDInput;
log.message(ProjectSuite.Variables.CBOSabreID0);
end;
end;
end;

 

When i set a breakpoint at the line "case varsp1 of" and step through it, it goes to the next line and then skips to the end.

 

If I execute the following modified code (used to debug) it works fine.

function GetCBOProfileSabreProfileID(varsp1);
var
page, obj;
begin
page := Sys.Browser('*').Page(EnvironmentSettings2.GetServerURL + '*');
obj := GetNativeWebObject(page, 'id', 'fieldAdditionalInfoSabreProfileID');
obj.ScrollIntoView(false);
Delay(1000);
obj.innertext;
obj := obj.innertext;
CBOSabreProfileIDInput := obj;
ProjectSuite.Variables.CBOSabreID0 := CBOSabreProfileIDInput;
log.message(ProjectSuite.Variables.CBOSabreID0);

//Assign var1 for the persistent variable
case varsp1 of
'CBOSabreID0':
begin
ProjectSuite.Variables.CBOSabreID0 := CBOSabreProfileIDInput;
log.message(ProjectSuite.Variables.CBOSabreID0);
end;
end;
end;

 

Please advise me on what I'm doing incorrectly.

 

Thanks,

Kim

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Well, the second block of code you are explicitly setting the value so the case statement doesn't really matter if it works correctly or not.

    So... the question is, when you set your breakpoint on your first block of code at the beginning of the case statement, if you bring up a Watch window on varsp1, what is the value?

     

    Keep in mind that the case statement is looking at the value of that parameter and attempting to compare it to a string of 'CBOSabreID0'.  If the string is not an EXACT match, the case will never trigger.  Additionally, if varsp1 doesn't actually CONTAIN a string, the case will never trigger. So... best debugging is to figure out what is being passed in and determine if the case you have defined is actually being met.

    • kimmatsumoto's avatar
      kimmatsumoto
      Contributor

      Hi,

       

      I think i did that:

      GetCBOProfileSabreProfileID(CBOSabreID0);

       

      Thanks,

      Kim

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Nope.  That passes in some unknown identifier CBOSabreID0.  You want to pass in a string.  So, it needs to read

         

        GetCBOProfileSabreProfileID('CBOSabreID0');

        Note the inclusion of the quotes indicating that what you're passing in is a string.  Again, the non-strict typing of JavaScript got you... you can create identifiers on the fly just simply by using them.  So, you had created an identifier of CBOSabreID0 that was empty and didn't actually contain the desired string.

         

        EDIT: Sorry, not JavaScript... DelphiScript.  But the same thing applies.  DelphiScript is not strongly typed either so it allows you do do some odd things with creating variables that can contain different values.