Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Puzzling Comparison
Message
From
23/06/2020 19:22:46
 
 
To
23/06/2020 06:42:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01674994
Message ID:
01675005
Views:
71
>In comparing a numeric field from a table against a character variable, I get unexpected results. For example...
>x='1234'
>y=1234 (numeric field from the table)
>
>I convert the numeric to character by...
>y=alltrim(str(y))
>
>for continuity sake, I do an alltrim on the character field too...
>x=alltrim(x)
>
>When I then do a compare of x and y, sometimes they're equal and sometimes they're not.
>
>It's probably something really basic that I'm missing, but I'm really puzzled.
>Any help, please?

Are the fields actually integer or is the issue the handling of decimals in the conversion? If decimals are involved, you should probably include the length and decimal parameters for STR(). Would Transform() give you better results than STR()?

Would it make more sense to go the other way and convert the string into a number and compare the numbers?

Thanks for the reply, Tamar. There are no decimals involved. One field is from a table and is numeric. The other is the result of a selection from a listbox and is character (but always an integer) . I've tried converting the character to numeric and comparing as well as converting the numeric to character and comparing. It seems to me that I ran into this very same problem a few years ago with another app, but for the life of me I cannot remember how that was resolved. I feel it had something to do with the fact that one of the values was from a table.

The irony of all this is that this has worked for years now. Now I'm adding a bit of extra code to do something else unrelated. The original code still works (the first time), but then after I do the new extra added routine and return to my listbox, the comparison fails. Really strange.

At my wits end!
Rich



Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform