06-20-2012 02:06 PM
Hello all,
I'm relatively new to LabVIEW, but I will try to explain the problem I'm having the best I can. Here's the problem:
1. Given a part number that is broken down like this: 0 0 0 0 . 0 0 0 0 0 . 0 0 0 0 0 0 <0> . 0 0 <0> The zeros enclosed in brackets mean they may or may not be there, depending on if an option is included in the part.
2. When a person enters a part number, I want LabVIEW to take the first two numbers, look in one table in a database.
3. Then, with the next two numbers, search a separate table in the same database and match these numbers.
4. Use the following three numbers after the two previously searched and find these in a different table in the same database.
This process continues until there are no numbers left. I want the user to be able to enter, for example 1234.56789.12345.67 and LabVIEW can say "OK, this part is from Series X, with a length of X, from drawing X, etc." Each set of numbers correspond to a feature of the part. All the tables are in the same database.
Can anyone point me in the right direction? I do have the database connectivity tool and I have successfully connected to the database. I used the examples within LabVIEW and can successfully complete the "Read All Data" VI example. What I need now is a way to search this database.
Thanks everyone!
Solved! Go to Solution.
06-21-2012 04:55 AM
Well, you have to questions in one here it seems:
a) String handling:
You should look into "Scan From String" and, as requirement for it, regular expressions.
b) Database Queries:
You should learn, how to formulate SQL Queries.
Since you are working with LV, you should also search the LV help for the quoted functions.
hope this helps,
Norbert
06-21-2012 06:32 AM
Norbert,
Thanks for your reply. I'll look further into it per your suggestions. Hopefully I can come up with something and post it here to get some feedback.
Thanks again,
Chris
06-21-2012 11:00 AM - edited 06-21-2012 11:01 AM
I'm still not sure on how to even begin dividing the string which is all numbers into separate pieces. Let me try to explain better by showing what I mean. I'll include a divider to show where I need to separate the string.
0 0 0 0 . 0 0 0 0 0 . 0 0 0 0 0 0 0 . 0 0 0
| | | | | | | | | | | |
So, after the string is separated it would be
00
00
000
00
00
00
000
000
From these separate strings, I want to search a database. So, the first two digits would search in the first table, the second two digits in the second table, and so on. Anyone?
06-21-2012 12:06 PM
If I understand your Q
String parsing can be tricky but LV has lots of tools to go about it.
Make a test wrapper VI with string input and outputs
In the VI Use all the string functions you think might bre helpful to get the result you want for each parsing.
Test each one to find the best for each field.
Nice thing about LV and string parsing is you can see results of a test immediately and try all sorts of stuff.
Good starting candidates are
String subset
Match Pattern
and
Scan from string
If the numbers are spaced with spaces don't forget to remove whitespace after each iteration in your loops as you progress through a string.
You might be able to get fancy and use a while loop with a shift register to parse or copy ions of the string for each "thing" you are looking for without really affecting the original string too.
Its all there for the testing.
06-21-2012 12:18 PM
Thanks for your reply. This is as far as I've gotten:
When I run the VI, it separates the strings as desired. However, it omits the leading zeros. This isn't good because the database that I'm going to be querying needs the leading zeros. Also, I need the periods in the part number, but everytime I run it with the periods I get the error: The input string does not contain data in the expected format.
06-21-2012 12:25 PM
You need to stay in the text domain. I don't know why you are doing what you are doing. You'll end up having to convert the numbers back to a string to use in an SQL query.
06-21-2012 12:28 PM
The part numbers are all digits. I need to break the numbers up, or so I thought, because each "set" of numbers corresponds to a table in a database. NYC, is there a different way to do this? Thanks for your help
06-21-2012 01:18 PM
break up the long string into substrings using String subset function
06-21-2012 01:25 PM
Try this. (I did not convert the strings to numbers but your SQL query will end up being a string anyway.)