04-05-2017 10:10 AM
Good Morning Motivators,
I was trying to write a VI which involves representing numbers in coded format, but I have no idea. Please help me if you can.
This is the question:
Suppose we want to represent numbers in coded format. Consider the following code:
1 = lv, 2 = ma, 3 = po, 4 = ni, 5 = be, 6 = ut, 7 = ke, 8 = su, 9 = lu, and 0 = ha
For example, the number 987 is written in coded form as lusuke. Create a VI that takes a string as an input and outputs the equivalent number on a numeric indicator. Display the number -1 if the input code does not translate.
04-05-2017 10:38 AM
You will need Search/Split Sting to get 2 characters at a time. From there, use a lookup table to convert your two characters into a number (hint: use Search 1D Array which will give you the index of the match or -1 if there was no match).
Give it a try. We will not do your homework for you. If you have specific questions, ask away.
04-05-2017 11:11 AM
Hello everyone!
Here is my solution. I need to work more in my discipline of programming.
If It works, It ain't stupid!
Regards!
04-05-2017 11:21 AM
General comment:
If you know how many times a loop will iterate, use a FOR loop. In this case, you can use an autoindexing input tunnel to tell the loop how many times to iterate. That would save you quite a bit of code in there (for FOR loop would just contain the Search 1D Array).
04-05-2017 12:35 PM
Define an enum that has your encodings, then use it to scan from string.
04-05-2017 02:25 PM
@paul_cardinale wrote:
Define an enum that has your encodings, then use it to scan from string.
There was a discussion a while back where I remember where this can lead to false matches. I can't remember why.
04-05-2017 02:41 PM
@billko wrote:
@paul_cardinale wrote:
Define an enum that has your encodings, then use it to scan from string.
There was a discussion a while back where I remember where this can lead to false matches. I can't remember why.
If there is not a match, you will still get a 0, so this will not meet the requirement of a -1 when there is an invalid code.
04-05-2017 02:51 PM
04-06-2017 08:42 AM
@paul_cardinale wrote:
Who'd have known I'd be using this very code today? 😉
04-06-2017 05:02 PM
Hi Jimbe,
I was looking at your snapshot and I had a quick question for you. How did you create the two tables ( One in pink and the other in blue)? Are they linked or something. I have trying to figure but no luck.
Thanks.
Vincent