LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Storing the data

Solved!
Go to solution

Hello, 

 

In the attached VI of simple calculator, I want to retain the first-operand data even when I press the operator button (=,-,*,/) multiple times or when i want to change the operator. How can I do it? 

 

Any help is appreciated. 

Thanks. 

0 Kudos
Message 1 of 11
(2,871 Views)

Which data are you talking about?

 

One thing I see is an unnamed string indicator.  (Show the label and give it a name!) That gets its value from the tunnel of the event structure.  But it only gets data in one case.  Because the tunnel is set to Use Default if Unwired, it gets default data, an empty string, when any other event case runs.

0 Kudos
Message 2 of 11
(2,832 Views)

Hey Ravens,

 

Thanks for the reply.

Please ignore the empty string. I should have removed it. My question is, if I perform this operation say 21-3 I get the desired result. But, if I do this, 21--3 (If I press the operator twice, the first operand '21' is lost and I understand why it will be lost.) I would like to retain the first operand even when i press the operator (--) twice. I hope you got my question. 

 

Thanks again. 

0 Kudos
Message 3 of 11
(2,821 Views)

Remember what the last button was by storing it in a shift register.  If you detect a new button is an operator that matches the one in shift register, you know you duplicated the button and ignore it.

0 Kudos
Message 4 of 11
(2,809 Views)

What if you want to calculate 21-(-3)?

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 11
(2,779 Views)

Hello Yamaeda, 

 

Nope. Not 21-(-3). I still want to calculate 21-3 but I press the - button twice/thrice or whatever. In our phyical calculator or windows calculator if you do like 21-----3 it is still 21-3 but in this code if I press the - button second time, my first operand (21) is lost and I understand why it will be lost but I'm thinking of a way to retain it even though I press - button multiple times. 

 

Thanks.

0 Kudos
Message 6 of 11
(2,777 Views)

Hi Ganny,

 

I understand why it will be lost but I'm thinking of a way to retain it even though I press - button multiple times. 

Think of a state machine:

1. state: input of first numeric operand (as long as the user inputs numeric chars)

2. state: input of operation (as long as the user inputs an "operation" char like +-*/)

3. state: input of 2nd numeric operand (as long as the user inputs numeric chars) (might even be the same as 1st state)

4. state: iput of "=" or "enter" (or similar): solve operation from stored inputs

Each state from 1 to 3 will store its input in a separate shift register…

 

Sometimes it really helps to develop an algorithm on a sheet of paper - BEFORE starting to code…

Best regards,
GerdW


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

Hello GerdW, 

 

Thanks for the valuable suggestion - to write the algorithm before starting the code. I should start practicing it. 

 

By the way, I will try it with State Machines. But, is there any way to get it done from this code? 

 

 

0 Kudos
Message 8 of 11
(2,769 Views)

Hi Ganny,

 

But, is there any way to get it done from this code?

When you mean your VI from your first message with "this": sure!

(Btw. what's the purpose of a wait function in parallel to your loop?)

 

All you need to do is to implement all those valuable suggestions you got so far…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 11
(2,764 Views)

Hello GerdW, 

 

That Wait Function don't have any purpose. I just didn't see it's there. I removed it. 

By the way, I still don't understand how I can modify the code to retain the first operand in case of multiple - sign presses. 

Can you throw some light on it for me?

 

Thanks

0 Kudos
Message 10 of 11
(2,760 Views)