Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Integer? Values Not Matching

1. ## Integer? Values Not Matching

The following if statement is not passing....
Can't seem to figure out why....

Code Snippet:
z = "342a";
x = substr(z, 1, 3);
y = int(x);

if(x == y)
{
PASS;
}

Ultimately what I am trying to do is grab a 3-character substr that I want to see is numeric AND is a whole number (which is what I was going for with the int() function).

Thanks for any assistance.

Oh, BTW, my watch list has x and y both equal to 342.

2. ## Re: Integer? Values Not Matching

Just a guess or two:
1) String versus integer - despite our expectations. WinRunner stores internally as string correct? int is an external function that truly is int and not string.
2) A bug

Possible workaround:

z = "342a";
x = substr(z, 1, 3);
y = int(x);
x = int(x); # Force conversion

if(x == y)
{
PASS;
}

OR,
Add 1 to both x and y after substr and int in order to force WRun to equivalent string storage.

3. ## Re: Integer? Values Not Matching

Try
if((x+0) == (y+0)) #Convert to number
{
PASS;
}

4. ## Re: Integer? Values Not Matching

Thats right problem is you are comparing string and integer which will always have different values. Either convert both of them to string or int. Above solution provided must work for you.

5. ## Re: Integer? Values Not Matching

you are comparing string and integer which will always have different values
<font size="2" face="Verdana, Arial, Helvetica">Well, hardly! In TSL, such comparisons USUALLY work, which I'm sure Jordan is aware of.

6. ## Re: Integer? Values Not Matching

I just tried it and it worked fine, using this code:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">z = &quot;342a&quot;;
x = substr(z, 1, 3);
y = int(x);
if(x == y)
{
pause(&quot;Pass&quot;
}
else
{
pause(&quot;Fail);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">It even worked if I did this instead:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">z = &quot;342a&quot;;
x = substr(z, 1, 3);
y = int(z); # &lt;&lt;&lt;=== Changed x to z
if(x == y)
{
pause(&quot;Pass&quot;
}
else
{
pause(&quot;Fail);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">(Using WR 7.5)

[ 06-29-2004, 06:31 AM: Message edited by: Charles Reace ]

7. ## Re: Integer? Values Not Matching

Hey Charles
Should you have == in your logic test?
Funny things happen with only one =

8. ## Re: Integer? Values Not Matching

For some reason, WR doesn't like the invalid code within the 'if' block. Replace it with 'exit;' and it works fine. Since TSL is a scripting language, if(strX == intX) is valid syntax.

9. ## Re: Integer? Values Not Matching

Originally posted by k1w1:
Hey Charles
Should you have == in your logic test?
Funny things happen with only one =
<font size="2" face="Verdana, Arial, Helvetica">Just a typo. It was "==" in the original, but I changed it to "=" just to see what that would do and forgot to change it back when I copied it here.

#### 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.