LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String numbers into dbl percision without dropping zeroes

Solved!
Go to solution

Hello all

I'm using Labview 2009, and have a String from Match Pattern, Match SubString that contains 5 digits. Example: 03926 Since the zero is a place holder to denote the 10,000's position, I can not lose it. I need to get that number into a Double Percision format in order to feed it back to an input that is also Double Percision. I have been trying this using Scan from String but can't seem to come up with the right format condition to keep my leading zero, or zeroes. Can Someone help me get past this knot?

0 Kudos
Message 1 of 9
(3,368 Views)

For the control / indicator, Right-Click -> Properties -> Display Format -> Use Minimum Field width.  Note that this is just display, the actual number is still just 3926, to convert it back to string the format is %06f

Jon D
Certified LabVIEW Developer.
0 Kudos
Message 2 of 9
(3,351 Views)

Thanks for the reply, yeah on the note I'll have to play with that part later also. What I would like to do is strip the return string from the sig. gen. down to just the 5 numbers. Exclude numbers like 010, or 001, 100 etc. those would be mode requests (or sends?) on the same line. All the 5 digit numbers are telling me that the sig. gen. is responding to my "u" by incrementing to frequency xxxxx, or "d", decrementing to frequency xxxxx. This 5 digit number I want to convert it to dbl percision, and feed it back to the knob/indicator programmatically keeping that display current with where the sig gen thinks it is. Right now the 001, 010, or 100 gets through as a match. It also skips displaying a match every other time even though the sig. gen. has received my command, stepped the frequency, and sent the 5 digit code. Instead of displaying a match, it says offset past match is -1. The next increament is off by 1, the next mis is off by 2, the next mis puts it off by 3 and so on. Hopefully my attachment took, but the "Manual Stepping Down" case structure is what I am experimenting with. the delays, and some of the stuff in there are experimental or obsoleted themselves after I learned more about Labview. I'm sure there is tons of stuff that is shotty programming in here FYI.

Thanks

0 Kudos
Message 3 of 9
(3,274 Views)

To match exactly five digits using the Match Pattern function, you'll want to use this syntax:

 

Leading Zero String Double.png

 

If you use [0-9]+, it'll match any sequence of digits in the string. String to Number will convert it to a double no matter how many leading zeros there are.

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
Message 4 of 9
(3,254 Views)

THAT, is the ah ha I needed! Thanks pangvady! I noticed something with my other problem where I don't get a match every other read. I was looking at the IO Trace, and in my attempt to just write the switch once, i had the case flip to a blank false side as soon as the switch unpressed. It looks as though that happens so fast that the case flips to false before it even gets to the read command so I can receive the sig. gen. 5 digits. I am guessing I should replace it with maybe a FOR Loop? Because they are both in a While loop, and I want them only used once every time their specific switch is closed. That is the only fix left that I am aware of. I can't wait to see how fixing my format string runs. NOW we are having fun. 🙂

0 Kudos
Message 5 of 9
(3,218 Views)

I know that some would disagree with me, but I might consider parsing out the whole message, depending on how complicated the message is, because you never know when you're going to need the other stuff.  It's usually quite trivial to do this, and you end up looking like the hero down the road if they ever need the info.  It's so nice to say, "already done".  😉

 

Other than that, I don't see a single subVI in the picture you posted.  That's like dumping all your text code into main().  It's probably going to be kind of tough to troublshoot.

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.
Message 6 of 9
(3,195 Views)
Solution
Accepted by Hobbs23

I think what you're trying to do is to read from the instrument if there are any bytes available to read and only write when a button is pushed. In this case, you'll want to put the write and read functions in their own case structures. This way, reading is decoupled from any button state.

 

Up Down Sig Gen.png

 

This code will work but, normally, event structures should be used for handling any user interface actions in order to get the best performance/readability/use of resources from your software.

 

http://zone.ni.com/reference/en-XX/help/371361N-01/glang/event_structure/

Feel free. Contact me for anything more,
    Pang

You too can be LabVIEW Awesome!
Message 7 of 9
(3,191 Views)

Hey Billko

I like the idea of having it all done and parsed out. As for subvi's, I've only made one once before, and I use it to pull this VI up from a splash screen, (Im not very good at it since buy the time I finish imagineering what I want to do by feel, I have this huge thing. I will work on it.  This is the first program I ever really did while I was teaching myself, so alot of the ground work was done before I ever learned about subvi's, or lots of other stuff. Thanks for the guidence.

Dan

0 Kudos
Message 8 of 9
(3,178 Views)

You do get what I am trying to do pangvady. Thanks, too much compartmental thinking on my part, I never thought to look at it as smaller tasks. That should do It for me. I really want to go back and redo everything but I bet we all think like that. I will just document, document, document. 🙂

Thanks for your help, ideas, and time.

Dan

Message 9 of 9
(3,173 Views)