Txt file read error

Hello
I have a problem when reading from a txt file when I put the item number to get me its name and price, an example in the items file there is
Code name price
0002,banana,35
2,Apple,20

When he comes with the class example, I want class 0002. The second class comes to me with the example that starts with 2, meaning it does not read 0 from the beginning. What is the solution to the problem?

1 Like

0002 is a string, 2 is a number. Your item_code.Text will need to contain 0002 in order to return that item.

1 Like

Could you explain to me please?

The string 0002 is not equal to number 2.
I think you have to explain better your goal, what you put in textbox, wich result expected.

Here's the problem
20220507_124858


20220507_124917

1 Like

Here is my problem, I don't know how to solve it

1 Like

can you attach a test aia ?

Write the following instead in the text file,
"0002",banana,35

This will give you the result.

Note that you wont be able to perform number operations on "0002".

Yes, I see your problem, in AI2 2 = 0002.....

Prevent the number/string conversion by making your code numbers actual strings by adding a text character to both sides of the test...

This way you do not have to edit/change your base data in any way.

You may want to choose a more obscure text character :wink:

1 Like

No need to poll. If others find it useful, they can like your post.

Here are some cases:

  • if you use the equal operator in the Logic drawer, your statement is not correct.

  • if you use the equal operator in the Math drawer, your statement is not correct, but:

  • if you use the equal operator in the Text drawer, your statement is correct.

Now that we see the author uses the Logic one, the program probably distinguished the two items as identical.

1 Like

But what you showed in the image is hard-coded right. That can't be used for variables.

Rather using a join block with an empty string as the second parameter will do the thing.

My solution will work for the OP's problem where AI2 treats "equivalent" strings and number the same.

An empty string will/may not work.

Hard coded in the blocks, yes, but it is only an assisted conditional test, and has not impact on the underlying data. You could potentially use this approach with any "variable", depending on the content and circumstances.

Why not use CompareText instead of Math = ?

Best answer :slight_smile:

thumbsup2

4 Likes

:grin::heart_eyes::heart_eyes::heart_eyes::heart_eyes::heart_eyes:yes is Best answer thank you very much for ALL

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.