LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with string to number conversion

Solved!
Go to solution

I am trying to display a receipt, after some items have been added.

The app works fine for one item, but when I add more than one, it displays a different value from what it should.

I'm also having problems in displaying the second and third item.

Can someone help me fix this vi?

Thanks in advance!

0 Kudos
Message 1 of 10
(3,734 Views)

I'm having a hard time running your VI because it requests a file to read that you didn't include.

 

A quick glance at your code, I think you might be having a problem with some of your tunnels.  Both in case structures and the event structure, you have tunnels that are set to use Default if Unwired.   And you don't have your wires going into all those tunnels.  I'm guessing that you are losing some of the data that you have maintained in your shift registers because of that.  It is unclear why you have 5 different shift registers.

0 Kudos
Message 2 of 10
(3,725 Views)

Sorry about that.

I will include both files now.

Download All
0 Kudos
Message 3 of 10
(3,718 Views)

That helped make the VI run.

 

It also really makes me believe your problem lies with all those "Use Default if Unwired" Tunnels and failing to wire all the cases through.

0 Kudos
Message 4 of 10
(3,656 Views)

@RavensFan wrote:

That helped make the VI run.

 

It also really makes me believe your problem lies with all those "Use Default if Unwired" Tunnels and failing to wire all the cases through.


To expand on RavensFan's thoughts:

 

When you specify Use Default if Unwired for a tunnel, you have to remember to manually make sure that every time you create a new case that you wire any data that is just "passing through."  It is VERY easy to forget and you won't notice until you realize that you are getting unexpected results.  Or you might never notice that you have bad data if it's buried deep.

 

A better way is to leave it as an "open square" so that the VI will have a broken arrow and won't run until you go and manually wire it.

 

The best way is to use the Linked Input Tunnel --> Create & Wire Unwired Cases which automatically wires any existing cases with no wires and any future cases that you add.

 

Honestly, there are few places I use the Use Default if Unwired in a case structure.  The notable exception is when the value is NOT being carried on a shift register AND the default value for the data type is acceptable, as is often the case when using a boolean to stop a loop, for example.  Even then, a common practice is to leave it as an "open square" and manually wire a constant to it.  This assures you that you have considered what the value should be for each case.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 10
(3,633 Views)

I just connected all the default if unwired tunnels and I also placed some probes on the string wire that carries the price and the wire thar carries the value after the string is converted into a number. The string gives me a result of 75 and the number gives me another value in the probes, and they should have the same value. The Vi is also not adding the results correctly. It also adds 2 items, but only if they Are from a different type, like DVDs and Mouse. Can someone please take a look at the VI I just uploaded, and try to fix it or at least tell me how to fix it?

Thanks!

0 Kudos
Message 6 of 10
(3,607 Views)

I changed the VI, but now it will not add the second item. I adds correctly when I have 1 inquantity, but adds incorrectly when I have more than 1.

0 Kudos
Message 7 of 10
(3,597 Views)

On the first run of your VI, I see data in the row 1.  Later, it gets replaced with header type of information.

 

I don't think we can help anymore with your VI.  Basically, your VI is not doing what you want it to, you have bugs in your logic, and you are the one who will need to figure that out.  User more probes, use highlight execution, to see how your code is operating as part of a normal debugging process and where the flaws in your code are occurring.

0 Kudos
Message 8 of 10
(3,584 Views)
Solution
Accepted by topic author Nando88

I just found the error. The error was being made in the conversion from string to number. I just used the Fract/Exp string to number, and it fixed the problem I was having.

0 Kudos
Message 9 of 10
(3,569 Views)

@Nando88 wrote:

I just found the error. The error was being made in the conversion from string to number. I just used the Fract/Exp string to number, and it fixed the problem I was having.


Very common mistake.  You were using Decimal String to Number, correct?  Unfortunately, the description you gave only said the answer was "different" than what you expected with no mention of whole numbers or decimals or anything like that.  If you did, the discussion would've most likely been one paragraph instead of one page.  (But the information about the default tunnel thingy was absolutely worth the discussion for you.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 10
(3,557 Views)