From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

If a string variable is empty, write "no info" in it

Solved!
Go to solution

Hello, I have 10 string variables where I want to write different information on them. But if I don't have that information for a variable, I want it to write "no info". I know I can make a comparison for every variable with an empty string constant and put a case, if it's true, write "no info" on it. But I don't know what is the easiest way, because doing it with 10 variables is not a hard job, but imagine if I had 100.

 

Inserting all in a array it's a posibility and put a comparison inside with a case structure. Is there any other better option?

0 Kudos
Message 1 of 10
(1,004 Views)

Hi lab,

 


@electronic_lab wrote:

Inserting all in a array it's a posibility and put a comparison inside with a case structure. Is there any other better option?


  • When there are a lot of values of the same datatype you should use an array.
  • To test for "empty string" you could use the EmptyString? function in the comparison palette.
  • To assign the "no info" constant I would use the Select function instead of a case structure: much more readable code…

@electronic_lab wrote:

Hello, I have 10 string variables where I want to write different information on them. But if I don't have that information for a variable, I want it to write "no info".


What are "variables" in your context? You know in LabVIEW the wire is the variable?

You might use sets or maps in recent LabVIEW versions when you want to handle key-value pairs. You can even initialize them (sets, maps, or your "variables") with "no info" and write the "known values" to the "variables"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 10
(999 Views)

As mentioned, your terminology is not clear at all and it would help if you could attach a small example VI.

 

Since there is no such thing as a "10 string variable", can we assume this is a string array with 10 elements?

 

In one possible scenario, easiest would be to initialize the array of the desired size with "no info", keep it in a shift register and then replace elements with valid data as it arrives. Where does the good data come from?

If most elements are "no info", a map as already suggested would be most efficient. There is no scenario where you would really need a case structure.

0 Kudos
Message 3 of 10
(970 Views)

To specify more, I want to write data in a database. This data is (for example): Name, Surname, Age, Gender, Adress... So i want that if I don't know the Adress for example, I let it empty, but when i press the OK button to insert in database, the empty adress enters as a "NO INFO" string. The problem is that I don't know how to do it in a simple way.

0 Kudos
Message 4 of 10
(965 Views)

Hi lab,

 


@electronic_lab wrote:

This data is (for example): Name, Surname, Age, Gender, Adress...


You still don't explain hwo you organize your data...

Do you use a cluster of strings? Or an array of strings? Or just a bunch of string controls scattered over the frontpanel?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 10
(962 Views)

@electronic_lab wrote:

The problem is that I don't know how to do it in a simple way.


The term 'In a simple way" is very vague and it means different things to different people.

 

So, is simplicity the only problem? Can you achieve what you want in a complicated way? Why don't you show us your code and we will simplify it for you!

0 Kudos
Message 6 of 10
(949 Views)

I have create a small VI of my original Vi. The part i want is where i press the OK button, there I want to write something where empty strings change to "NO INFO"

0 Kudos
Message 7 of 10
(942 Views)
Solution
Accepted by topic author electronic_lab

Well, here's what I might do:

 

altenbach_0-1708329682782.png

 

 

 

Some comments:

 

  • Your buttons should be latch action and placed inside their respective event cases
  • None of your sequence structures are needed. 
  • None of your local variables are needed. Why no connect to the terminals??
  • It is super annoying having the front panel and diagram maximized to the screen
  • Currently, the timeout event is pointless. What are your plans there?
  • ...

 

0 Kudos
Message 8 of 10
(933 Views)

Thank you for the solution, I'm still learning of Labview because I´m pretty new. Answering your questions, the program I attached is a little part of a bigger program, and I just copied the part i had doubts.

 

Yes, i will use latch action buttons, I didn't change it yet. I have another event case to update some other variables taken from another database. And another one to open a file where there is the information name, surname and age, and it writes automatically. So as I need to use variables in those events, I just put all variables initialized in a first sequence structure.

 

I don't have plans for my timeout yet, so I may delete it.

 

I don't understand what you mean with the front panel and diagram maximized to the screen, could you explain it more?

0 Kudos
Message 9 of 10
(892 Views)

Hi lab,

 


@electronic_lab wrote:

I don't understand what you mean with the front panel and diagram maximized to the screen, could you explain it more?


When you "maximize" a window then it covers the full screen (aka monitor). This is just annoying, especially for smaller frontpanels/block diagrams.

(In Windows there are 3 symbols in the upper right corner of the window border, to minimize/maximize/close the window. You clicked the maximize symbol...)

 


@electronic_lab wrote:

So as I need to use variables in those events, I just put all variables initialized in a first sequence structure.


You still use the word "variables": please use the word "data" instead - and try to THINK DATAFLOW!

In LabVIEW the wires are "variables", while frontpanel elements (controls/indicators) are used as data source/sink!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 10
(887 Views)