App Designer how to set value for edit field (numeric)

Hello,
I'm having issues with the simplest of things. I have an app that opens a "Parameters" window. In this window I should be able to set system parameters, such as:
Carrier Frequency, Carrier Power etc.
I'm trying to edit the initial value from 0, to some default value defined in my main app. I'm not even at a stage of changing this value, just trying to grab the default instead of 0.
From the code view in the app in the "create components function", if I set an initial value manually it adds a line of app.CarrierPowerEditField.Value = 15;
I try to add this line manually at the startup function, but this affects exactly nothing for the actuall app. I still get an edit box with "0".
Only if I add a "set" button, upon press of which it will set app.CarrierPowerEditField.Value = 15 will the value change.
I can add a button for grabbing the default values, but I run into a different issue:
In the main app I create a variable as public property
DefCarPower = 15;
But if I write
app.CarrierPowerEditField.Value = app.DefCarPower;
it says "Unrecognized method, property, or field 'DefCarPower' for class 'SecondWindow'."
What am I doing wrong?

댓글 수: 1

Is this "Parameters" window a dialog box created with inputdlg?
Is the "Parameters" window an app? If so, which startup function are you editing, this app or the main app?
Do you have code that you can share?

댓글을 달려면 로그인하십시오.

 채택된 답변

Kevin Holly
Kevin Holly 2022년 10월 17일
If the SecondWindow is an app that was called from the mainapp. You will need to call the property value from the mainapp. The current command calls from the SecondWindow app and it does not find it.
It should be something like this:
app.CarrierPowerEditField.Value = app.Callingapp.DefCarPower;

댓글 수: 7

Egor Liokumovitch
Egor Liokumovitch 2022년 10월 17일
편집: Egor Liokumovitch 2022년 10월 17일
Thank you so much!
Now this mistery is solved for me. Thank you!
The only minor issue is that if the value of CarrierPower is left at 0, the app.CarrierPowerEditField.Value field is not created and this doesn't work.
If I set it to any value, say 5 - this field is created and then by pressing a button it grabs and edits the value.
But the main thing is that if I put this line in the startup function it immediately grabs the value.
Thank you again!
When you define the property value DefCarPower in the mainapp, do you initially give it a value?
properties (Access = public)
DefCarPower = 0;
end
or do you have it as:
properties (Access = public)
DefCarPower
end
Yes, I have an initial value.
So If I put
app.CarrierPowerEditField.Value = app.Callingapp.DefCarPower;
into a button press callback, it won't grab the value unless I set app.CarrierPowerEditField.Value initialy to something non-zero.
But that is not a huge issue because the plan was to grab all the default values and show them in the second window. Once all of them are shown, the user can decide if he wants to change any of them.
I am not sure how your app is setup.
My guess so far is that you have a mainapp with a property variable, DefCarPower. The mainapp calls a SecondWindow app, where you want to change editfield's value based on the property variable , DefCarPower, in the mainapp.
Can you confirm if this is the case?
From the information I have, I'm not sure why app.CarrierPowerEditField.Value cannot be zero.
I have another question. Is the property variable, DefCarPower, defined in the UI of the mainapp?
The Main window was setup like this:
properties (Access = private)
ParameterBox % Dialog box app
PlotBox
end
properties (Access = public)
DefCarrierFreq = 700e6;
DefCarrierPower = 15;
DefDataCaptureSize = 10e6;
DefSR = 2.5e6;
DefInpAtt = 0;
DefIFGain = 0;
DefIDC = 0;
DefQDC = 0;
DefGainMis = 0;
DefPhaseMis = 0;
DefLOMatch = 0;
FBGInter
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11
end
In the other windows I was setting the callback for the button:
% Button pushed function: SetButton
function SetButtonPushed(app, event)
app.CarrierPowerEditField.Value = app.CallingApp.DefCarrierPower;
end
For some reason it was saying that CarrierPowerEditField.Value is an unknown, and it was missing from the creation components:
app.CarrierPowerEditFieldLabel = uilabel(app.UIFigure);
app.CarrierPowerEditFieldLabel.HorizontalAlignment = 'right';
app.CarrierPowerEditFieldLabel.FontName = 'Lucida Sans Unicode';
app.CarrierPowerEditFieldLabel.Position = [23 459 83 22];
app.CarrierPowerEditFieldLabel.Text = 'Carrier Power';
but the second I manualy set the value of this property to something non zero it was created and became
app.CarrierPowerEditFieldLabel = uilabel(app.UIFigure);
app.CarrierPowerEditFieldLabel.HorizontalAlignment = 'right';
app.CarrierPowerEditFieldLabel.FontName = 'Lucida Sans Unicode';
app.CarrierPowerEditFieldLabel.Position = [23 459 83 22];
app.CarrierPowerEditFieldLabel.Text = 'Carrier Power';
app.CarrierPowerEditField.Value = 5; %%<---
And then by pressing a button it was running correctly. Maybe there was some other issue in the code.
I just put all the default values in the beggining and it grabs the values perfectly:
function startupFcn(app, caller, sz, c)
% Store main app object
app.CallingApp = caller;
% Process sz and c inputs
app.CarrierPowerEditField.Value = app.CallingApp.DefCarrierPower;
app.CarrierFrequencyEditField.Value = app.CallingApp.DefCarrierFreq;
...
Note, one says CarrierPowerEditFieldLabel and the other CarrierPowerEditField
Please see the two apps attached.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Timetables에 대해 자세히 알아보기

태그

질문:

2022년 10월 17일

댓글:

2022년 10월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by