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:
cart_name = "Mary's cart" & run_num
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?
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%"