LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding spacing between array when exporting to Notepad

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!

Download All
0 Kudos
Message 1 of 14
(3,527 Views)

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".

Message 2 of 14
(3,501 Views)

And here's an alternative way to generate the lotto numbers. 

Message 3 of 14
(3,496 Views)

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.

Message 4 of 14
(3,493 Views)

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.

 

simplelotto.png

Message 5 of 14
(3,483 Views)

Just FYI, in >LV17SP1 you can use the Shuffle 1D Array.vim.

 

Using this VI, you can choose to shuffle either numbers or strings.

 

Shuffle.png

 

@Gmille: See you at the Dutch NI Industry Summit?

0 Kudos
Message 6 of 14
(3,447 Views)

@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?

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 7 of 14
(3,430 Views)

@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. 😄

0 Kudos
Message 8 of 14
(3,427 Views)

@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.

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 9 of 14
(3,418 Views)

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!


Capture2.JPG

 

 

0 Kudos
Message 10 of 14
(3,410 Views)