10-07-2018 12:00 PM
In the following VI i have created a random generator for all unique numbers to be exported to a Notepad file, upon opening the file i noticed all the numbers are stuck to each other. I have tried to convert to string and add a space before placing it into the Array but then the loop to check if its unique doesn't seem to work anymore. Is there an option to export numbers like this with spaces between them?
Lotto Random is the random generator as a SubVI.
Ps: i have also tried to export it to a CSV using tab constants to space the 3 parts of text ('The winner is', numbers, timestamp) in different columns but it still writes it all out as 1 column, doesnt tab work like that in Labview?
Thanks in advance and kind regards!
10-07-2018 02:03 PM - edited 10-07-2018 02:08 PM
Notepad does not display tabs correctly, you could use a format with fixed field width and space as delimiter.
You could also e.g. open your output in excel or word instead.
Your code has missing subVIs, so we cannot test ( I guess your other attachment might be the missing subVI). Lotto numbers are integers, so why is there orange and coercions at all?
There is no need to attach the *.lvproj file, but next time please put all attachments into a zip file.
@gmille wrote:
In the following VI i have created a random generator for all unique numbers to be exported to a Notepad file, upon opening the file i noticed all the numbers are stuck to each other. I have tried to convert to string and add a space before placing it into the Array but then the loop to check if its unique doesn't seem to work anymore. Is there an option to export numbers like this with spaces between them?
The subVI should not operate on strings and should still return a numeric array as before. To convert the array to a string with defined delimiters, use "array to spreadsheet string".
10-07-2018 02:11 PM
And here's an alternative way to generate the lotto numbers.
10-07-2018 02:17 PM
Note that your method of generating random numbers is flawed, because edge values are generated with half the probability of other values. The use of "round to nearest" is incorrect.
10-07-2018 02:51 PM
Here's a simple alternative (no code, see if you can create it). Note that you could also use "format into file" directly, combining the last two operations inside the loop. If you want, you can sort the entries.
Be aware that using a variable number of spaces between numbers makes it slightly more difficult to read it later with a program.
10-08-2018 03:03 AM
Just FYI, in >LV17SP1 you can use the Shuffle 1D Array.vim.
Using this VI, you can choose to shuffle either numbers or strings.
@Gmille: See you at the Dutch NI Industry Summit?
10-08-2018 10:32 AM
@altenbach wrote:
Notepad does not display tabs correctly, you could use a format with fixed field width and space as delimiter.
You could also e.g. open your output in excel or word instead.
Your code has missing subVIs, so we cannot test ( I guess your other attachment might be the missing subVI). Lotto numbers are integers, so why is there orange and coercions at all?
There is no need to attach the *.lvproj file, but next time please put all attachments into a zip file.
@gmille wrote:
In the following VI i have created a random generator for all unique numbers to be exported to a Notepad file, upon opening the file i noticed all the numbers are stuck to each other. I have tried to convert to string and add a space before placing it into the Array but then the loop to check if its unique doesn't seem to work anymore. Is there an option to export numbers like this with spaces between them?
The subVI should not operate on strings and should still return a numeric array as before. To convert the array to a string with defined delimiters, use "array to spreadsheet string".
As far as I can tell, Notepad does display tabs correctly. You just can't set the tab stops. Or maybe that's what you meant?
10-08-2018 10:45 AM
@billko wrote:
@altenbachs far as I can tell, Notepad does display tabs correctly. You just can't set the tab stops. Or maybe that's what you meant?
Yes, they display as single spaces in notepad. You can't even tell if they are tabs or spaces. That's what I meant.
Useless for table formatting unless you have fixed field widths. At least notepad uses a monospaced font for display. 😄
10-08-2018 11:58 AM
@altenbach wrote:
@billko wrote:
@altenbachs far as I can tell, Notepad does display tabs correctly. You just can't set the tab stops. Or maybe that's what you meant?Yes, they display as single spaces in notepad. You can't even tell if they are tabs or spaces. That's what I meant.
Useless for table formatting unless you have fixed field widths. At least notepad uses a monospaced font for display. 😄
That's one reason I haven't used Notepad in... I can't remember the last time I opened it on purpose.
10-08-2018 12:51 PM - edited 10-08-2018 12:55 PM
Thank you very much for your help everyone! I was able to understand the different steps used in the shown program with the exception of 1 being the format string constant at the top. What does the %s do? Also i have noticed that there is a \ in front of the string constant, what does this do? When outputting my numbers now it does it all correctly but after a break to the new line (because of the \n if i understand it correctly?) it starts with a break like shown in the picture. Is this related to that \ at the front of the constant?
I have looked at the type of the array and indeed it should come out as an array of integer values but it shows as an array of doubles, any way to change this without having to make a new array? Thanks again!