Forum Discussion

DCat1223's avatar
DCat1223
Frequent Contributor
5 years ago
Solved

Save first few digits of a string as a variable

Good morning.  I have a Keyword test, using VBScript.  As part of this test, I have to have the script enter the base pay for a worker being hired.  The UI actually lists a Pay Range in a field that ...
  • tristaanogre's avatar
    5 years ago

    Well, first of all, your "Mode" should be Onscreen Object Property, not object, since contentText is a property

    Secondly, this is why you should learn some scripting coding because this is alot easier to write a simple script procedure to do the parsing.

     

    What I see is that you need to get the first part of the string up to the first "space" character because I'm assuming that the base pay won't always be 5 characters long... might be longer, might be shorter... so you need your code to grab a variable length.

     

    Here's how I'd write it in JAvaScript code.  You SHOULD be able to adapt this to VBScript as I'm using TestComplete objects/methods rather than native code.  

     

    function getBasePay(basePayString) {
        aqString.ListSeparator = " ";
        result = aqString.GetListItem(basePayString, 0);
    aqString.ListSeparator = "|"; }

     

    If you want to write it as a single line expression, to use in a keyword test, that can be done, too, but it's a bit more convoluted.

     

    aqString.SubString(<your property>, 0, aqString.Find(<your property>, " ") + 1)
  • DCat1223's avatar
    DCat1223
    5 years ago

    Thank you so much tristaanogre  and hkim5 .  Between the two of you I was able to write a basic script that worked!  tristaanogre , you are correct, I do need to learn to write script.  I have known this for a long time.  Just need to do it.  Thank you both again.