SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Sep 2002
    Location
    Redwood City, CA, USA
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    How to declare value appended with global value

    Hi All,

    I just started using QTP and VB Script last week. I'm trying to create a new variable "cart_name" which is made up of a string like "Janice's cart" and appended with a run number (a variable set in the Global data sheet). For example: cart_name is "Janice's cart 2" with run_num a global variable set to 2. My statements look like this:

    Dim cart_name
    cart_name = "Mary's cart" & run_num
    Browser("Home").Page("Home_2").WebEdit("name").Set cart_name

    When I run the test, the object cart_name is not set correctly. It only picks up Mary's cart but not the run_num which should be appended. Can someone please let me know what I'm doing wrong?

    Thanks,
    Janice

  2. #2
    Advanced Member
    Join Date
    Mar 2007
    Location
    Salt Lake City, UT, USA
    Posts
    606
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to declare value appended with global value

    Your concatenation is correct. Although, you might want to add a space after the cart: cart_Name = "Mary's cart " & run_num (the space is not necessary, but it will make it match your example where you have a space between "cart" and "2").

    Your syntax should work.

    Are you sure of what value is in run_num? Maybe run_num is empty (no value assigned to it) so it is concatenating an empty value at the end of "mary's cart".

    Maybe add a msgbox line right before your to verify what the value of run_num is:

    msgbox ">>>" & run_num & "<<<"

    For kicks, you could modify it to cart_name = "Mary's cart" & CStr(run_num) but QTP will convert a number to a string automatically when you use the & operator, so this isn't necessary (but it makes the script a little more clear if someone else is reading it and trying to understand your intent).
    "The last 10% of any software project will take 90% of the budgeted time. The first 90% will take the other 90%"

  3. #3
    Advanced Member
    Join Date
    Mar 2007
    Location
    Salt Lake City, UT, USA
    Posts
    606
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to declare value appended with global value

    Oh, I was assuming that run_num is a variable in your script, and that you were assigning the value of run_num earlier in the script.

    Maybe you just wanted to reference the value straight from your datatable? Maybe "run_num" is the name of a column (parameter) in your datatable?

    If so, you need to use:

    cart_name = "Mary's cart" & DataTable("run_num", dtGlobalSheet)

    (you don't need the dtGlobalSheet since QTP always looks there first - I just added it for clarity)
    "The last 10% of any software project will take 90% of the budgeted time. The first 90% will take the other 90%"

  4. #4
    Junior Member
    Join Date
    Sep 2002
    Location
    Redwood City, CA, USA
    Posts
    20
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: How to declare value appended with global value

    Hi Blake,

    You're absolutely right. I needed to reference run_num as a column in my Global datasheet. The code works now. Thanks a bunch.

    Janice

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:31 AM.

Copyright BetaSoft Inc.