LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

A simple calculator

Solved!
Go to solution

Hello. I just started LabVIEW for work.

I should make a simple calculator with result saving/loading functions.

But I have a problem with that.

So could you help me if possible?

 

kimtae_0-1628952605974.png

 

1.Front panel is like this.

 After inserting numbers and selecting operator, the result is displayed. 

 But I want the result is displayed when '= button' is clicked not when selecting   operator like a normal calculator.

 How can I do that?!

 I tried that with a event case but it did not go well...

 

kimtae_1-1628953549784.png

kimtae_2-1628953559747.png

 

2. I wanna display data to save on the right side while save button is true.

    Now it is like 54 65 3510. But I wanna insert the operator between them like

    55 x 65 3510. But I don't know how to do that.

 

3.  And I tried to save data to .txt or .csv file.    

     I hoped just one of the two ways would succeed.

     But the data is renewed not piled up.

     I wanna the data to be piled up  not renewed.

 

Sorry for many questions.

Thank you for reading this! 

 

 

 

0 Kudos
Message 1 of 9
(3,093 Views)
Solution
Accepted by topic author kimtae

@kimtae wrote:

Hello. I just started LabVIEW for work.

 


How much LabVIEW did you know before that? Did you write the current code or did you find it somewhere on the web?

 

As a first step, get rid of all these value property nodes. None are needed. (You can use a local variable to update a control if needed. Much more efficient). Most "states" should be kept in a shift register. You can have an event for the entire cluster. No need for all these separate events (e.g. CLR) All differences can be handled in a case structure.

 

Compare the following code (bottom alternative is much cleaner. No hidden cases!:

 

altenbach_0-1628971995181.png

 

 

You can append whatever you want to the string in the shift register. There are no restrictions. What matters is how to parse it into numeric math.

 

To append to an existing file, you can wire a TRUE to the "append?" input. It might be more efficient to use lower level file IO. Open the file once before the loop and keep appending as needed. Close when the program ends.

 

I think you can simplify your code to 20% of what it currently is. After that, implementing your additional requirements should be trivial.

0 Kudos
Message 2 of 9
(3,063 Views)

Hello. I just started LabVIEW and this is my first time.

I have used this program for a week until now without any education.

I just watched the Youtube to learn this program.

And I wrote this code watching the Youtube. 

But there was not the same code on Youtube that I want write.

So I'm so confused whether to try to finish this assignment and learn in the process or to start with a book for LabVIEW and an easier example.

 

Anyway thank you for reading my poor explanation and giving me a comment.

It was very helpful although I can't understand fully what you want to say.

 

I solved two of the three problems I wrote with your comment.

But I want to show the result of calculation when I click the =button not when change the 

value of 'operator selection'.

Could you give me any idea for that?

 

 

 

0 Kudos
Message 3 of 9
(3,026 Views)

@kimtae wrote:

But I want to show the result of calculation when I click the =button not when change the 

value of 'operator selection'.

 


I can't find an equal button on your front panel, so you could add one and create an event for it. (Or do you mean the = button on the keyboard?)

 


@kimtae wrote:

Hello. I just started LabVIEW and this is my first time.

I have used this program for a week until now without any education.

I just watched the Youtube to learn this program.

And I wrote this code watching the Youtube. 


There is a lot of garbage on YouTube and you probably need more LabVIEW experience to tell if video advice is good or bad.

 

I have never seen a commercial calculator with two number indicators and a number selector. Maybe you want to write something that has a more conventional user interface. Do a google search for "calculator" and look at some pictures.

 

Try to start with the training resources listed on the top of the forum. There are also a lot of examples that ship with LabVIEW (menu...help...find examples). Finally, you can also search the forum here. There are plenty of good examples.

0 Kudos
Message 4 of 9
(3,016 Views)
Solution
Accepted by topic author kimtae

@altenbach  작성:


I can't find an equal button on your front panel, so you could add one and create an event for it. (Or do you mean the = button on the keyboard?)

I will add an equal button on the front panel like this!

kimtae_2-1629078287297.png

 


@altenbach  작성:


There is a lot of garbage on YouTube and you probably need more LabVIEW experience to tell if video advice is good or bad.

 

I have never seen a commercial calculator with two number indicators and a number selector. Maybe you want to write something that has a more conventional user interface. Do a google search for "calculator" and look at some pictures.

 

Try to start with the training resources listed on the top of the forum. There are also a lot of examples that ship with LabVIEW (menu...help...find examples). Finally, you can also search the forum here. There are plenty of good examples.


A garbage kkk And I also have never seen a calculator like this. kkk 

You are right. I need more experience to judge whether the video is good or not. 

And the training resources you mentioned is here?

People wrote comments about the example code and it helps me wheter it is good or not. Thank you!

 

0 Kudos
Message 5 of 9
(2,999 Views)

I'm making a simple calculator.

Now the system is like this.

kimtae_0-1629708746656.png

 

kimtae_1-1629708823333.png

 

 

 

 

 

 

1.Input number1 

2.Select number2 with the 'number_selection' control.

3.Input number2

4.Select the operator with the 'operator_selection' control.

5.Click =button to output the result.

 

But I wanna change this system more simple like this.

1.Input number1 

2.Select the operator with the 'operator_selection' control.

3.Input number2  

4.Click =button to output the result.

 

I don't know how to make the process from the second step to third one

Could you give me an advice?.

0 Kudos
Message 6 of 9
(2,920 Views)
Solution
Accepted by topic author kimtae

For reference, this is a continuation of this thread.

 

(... and please only use normal characters in file names. Users with English windows cannot open your attachment)

0 Kudos
Message 7 of 9
(2,868 Views)

Thank you for the comment.

I will search other calculator examples more!

And I didn't know that Engish window can only open English attachment. Thank you!

My file is like this.

0 Kudos
Message 8 of 9
(2,857 Views)

Looks like a school assignment, not "work". I hope you don't expect a final solution to be handed to you, because that would be helping you to cheat and not helping you to master LabVIEW. Having said that, I can still give you some ideas that will help you not only with this LabVIEW assignment but with other ones too, and, actually, not only with LabVIEW.

 

Take a "bird eye view" of this application. What are some very general features of it? On the very top level how does it work? Forget that it is a calculator for a moment. This is an application that reacts to some events (which can happen at any moment, user pushing buttons in this particular case). How does it react? By running some actions. So this a REACTIVE discrete event system. Now what else can we say about how it works (reacts)? We can notice that at least sometimes what it should do when a user pushes a particular button depends not only on which button was pushed but also on something else, in this case on what the user has already done before, earlier (which buttons were pushed BEFORE). That "something" is called state. So this system (application, program) on the very top level works like this: It receives an event (some button was pushed) and then depending on 1) which particular event it is (which particular button was pushed) AND 2) which state the program is in at that moment, it performs some action(s) AND possibly (sometimes) changes its state. Note that the entire behavior of the system can be described as a collection of statements in the following form: "When event E1 happens AND the system is in state S1, actions A1,A2 should be run AND the system transitions to state S2. When event E1 happens AND the system is in state S2...". So the system can be modeled as a Mealy state machine. https://en.wikipedia.org/wiki/Mealy_machine

Apparently not only this calculator program can be modeled this way but a whole class of applications (and/or their individual parts). So if we implement a generic Mealy state machine we can then create all those applications much faster and with more similarity to each other, which makes them ALL easier to read, understand, and, hence, modify in the future. You can start with this design pattern (template), for example:

https://forums.ni.com/t5/Reference-Design-Content/Event-Driven-Queued-State-Machine-EDQSM/ta-p/38419...

0 Kudos
Message 9 of 9
(2,818 Views)