Matlab update popmenu string - matlab
I have a GUI which has a lot of menus associated with radiobuttons. Menus or popmenus will be available to edit or select only if the radiobuttons next to them is selected.
Among these menus I have 2 popmenus associated to a radiobutton. In the first popmenu I have set up in the string 3 different choices and if I take choice 1 and 2 the second popmenu will propose a string with 5 choice. But if I select choice 3 in the second popmenu I have only it will change the string of the popmenu 2 and all the proposition will be different.
To do that I have a function which works but the only problem is that to see the change of string in the popmenu 2 I need to unselect and select again the radiobutton. Is there a way to refresh the popmenu 2 choices when I change the selection in popmenu 1?
function h0=exemple
%KGUI4N construction de la boite de dialogue pour KGEXEC4N
%CAVIAR2, © ALSTOM + OL 1999/12-2003/03
blanc=[1 1 1];
gris=blanc*0.75;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%figure
h0=figure(...
'Units','characters',...
'DefaultUicontrolUnits','characters',...
'Color',gris,...
'IntegerHandle','off',...
'MenuBar','none',...
'Name','Norme harmonique',...
'NumberTitle','off',...
'Position',[100 30 110 25],...
'Resize','on',...
'Tag','NormeDlg',...
'WindowStyle','modal',...
'ToolBar','none');
%titre
uicontrol(h0,'Style','text',...
'BackgroundColor',gris,...
'HorizontalAlignment','center',...
'Position',[10 22 85 1],...
'String','Choix du gabarit à tracer en superposition sur les spectres');
%bouton OK
uicontrol(h0,...
'BackgroundColor',gris,...
'Callback','close(gcbf)',...
'Position',[27 0.5 16 2],...
'String','OK',...
'Tag','NormeOK');
%bouton annuler
uicontrol(h0,...
'BackgroundColor',gris,...
'Callback','close(gcbf)',...
'Position',[51 0.5 16 2],...
'String','Annuler');
%bouton aide
uicontrol(h0,...
'BackgroundColor',gris,...
'Position',[75 0.5 7 2],...
'String','?');
%Buttongroup1
bg = uibuttongroup('Visible','on',...
'BackgroundColor',gris);
%Aucune
ra(1) = uicontrol(bg,'Style','radiobutton',...
'BackgroundColor',gris,...
'Position',[5 19 30 1.7],...
'String','Aucun',...
'Tag','Norme0');
uicontrol(h0,'Style','text',...
'HorizontalAlignment','left',...
'BackgroundColor',gris,...
'Position',[35 19.35 7 1],...
'String','--',...
'Tag','Param0');
%IEEE519
ra(2) = uicontrol(bg,'Style','radiobutton',...
'BackgroundColor',gris,...
'Position',[5 17 30 1.7],...
'String','IEEE519 (2014)',...
'Tag','Norme519',...
'TooltipString','Param519-1');
prmsA{2} = uicontrol(h0,'Style','popupmenu',...
'BackgroundColor',blanc,...
'Position',[35 17 17 1.7],...
'String',['120V-69kV|70-161kV|162kV & +'],...
'Tag','Param519-1',...
'TooltipString','Niveau de tension considéré',...
'Value',1,...
'Enable','off');
prmsA{2}(2)=uicontrol(h0,'Style','popupmenu',...
'BackgroundColor',blanc,...
'Position',[53 17 18 1.7],...
'String','???',...
'Tag','Param519-2',...
'TooltipString','ISC/IL = courant de court-circuit sur courant maximum',...
'Value',1,...
'Enable','off');
set(bg,'SelectionChangeFcn',#(o,e)bgChangeFcn(o,e,prmsA))
movegui(h0,'center')
function bgChangeFcn(src,event,prms)
allprms = [prms{:}];
set(allprms,'Enable','off');
lbl=get(event.NewValue,'TooltipString');
if strcmp(lbl, 'Param519-1')
hno=[findobj(allprms,'Tag','Param519-1')
findobj(allprms,'Tag','Param519-2')];
Scr519(hno(1:2));
else
set(findobj(allprms,'Tag',lbl),'Enable','on');
end
function enable(h)
set(h,'Enable','on')
%%%%%%%%%%%%
function Scr519(h)
enable(h)
x=get(h(2),'Value');%n° ISC/IL en cours
switch get(h(1),'Value')
case {1,2}
if (x<1)||(x>5),x=1;end
ch='Iscr<20|20<Iscr<50|50<Iscr<100|100<Iscr<1k|1000<Iscr';
drawnow
case 3
if (x<1)||(x>3),x=1;end
ch='Iscr<25|25<Iscr>50|Iscr>=50';
drawnow
otherwise
error(kverranorm(6))
end
set(h(2),'String',ch,'Value',x)
The function that allow to update the popmenu string is the last one. It works but I would like to see the update without having to unselect and select the radiobutton.
Related
stockage in structure and iteration
I would like to understand one thing : When I write : Propreties.Device.Time = Data.Device(lobo(:,2),1) - Data.Device(lobo(:,1),1) I obtain a stockage of all the differencies (it's great) But when I write : Propreties.Device.Prop = sum(Data.Device(lobo(:,1) : lobo(:,2)),2)*dt I don't obtain a stockage of all results (that I would like to obtain as previous exemple) but an overwrite of each of them so at the end I have only one value :-/ Could someone explain to me what differs between the two examples and what I could implement to obtain in the second example the same type of result as in the first (ie a list of results and not a single result) (without making a loop) ? (Matlab verison : R2017a) Some data for exemple : Data.Device = [1.86000000000000 675 0;1.87000000000000 685 0;1.88000000000000 695 0;1.89000000000000 705 0;1.90000000000000 710 5;1.91000000000000 715 50;1.92000000000000 700 120;1.93000000000000 685 180;1.94000000000000 655 235;1.95000000000000 620 285;1.96000000000000 565 305;1.97000000000000 505 315;1.98000000000000 435 335;1.99000000000000 360 345;2 285 355]; lobo = [1 5; 6 15]; dt = 0.01 Propreties.Device.Time = Data.Device(lobo(:,2),1) - Data.Device(lobo(:,1),1); Propreties.Device.Prop = sum(Data.Device(lobo(:,1) : lobo(:,2)),2)*dt
Text file processing in Matlab
I have a text output from a program with a set format. I need to parse ~200 of them to extract an information. I tried in MATLAB with 'textscan' but did not work. Following is the input: MOTIFS SUMMARY: 1) TTATAGCCGC (GCGGCTATAA) 1.986 2) AAACCGCCTC (GAGGCGGTTT) 1.865 DETAILED RESULTS: 1) TTATAGCCGC (GCGGCTATAA) 1.986 Matrix: MAT1 TTATAGCCGC A 0.1249 0.177 0.7364 0.1189 0.7072 0.1149 0.09858 0.1096 C 0.0899 0.07379 0.1136 0.1298 0.08662 0.1293 0.7528 0.721 G 0.06828 0.1284 0.07195 0.1031 0.1352 0.6708 0.05556 0.0713 T 0.7169 0.6209 0.07802 0.6482 0.07096 0.08492 0.09305 0.09804 OCCURRENCES: >GENE_1 1 TTATAGCCGC 1 561 + >GENE_2 24 TAATAGCCGC 0.928699 762 - >GENE_3 10 ATATAGCCGC 0.904905 185 - >GENE_1 7 TTATAGCAGC 0.901785 726 + ********** 2) AAACCGCCTC (GAGGCGGTTT) 1.865 Matrix: MAT2 AAACCGCCTC A 0.653 0.7401 0.7763 0.1323 0.09619 0.09134 0.07033 0.1383 C 0.1163 0.07075 0.09441 0.749 0.6347 0.1132 0.6559 0.6982 G 0.09136 0.09402 0.07385 0.04209 0.1799 0.7332 0.1241 0.07568 T 0.1393 0.09518 0.05541 0.07659 0.08921 0.06234 0.1497 0.08786 OCCURRENCES: >GENE_1 21 AAACCGCCTC 1 963 + >GENE_2 14 AAACGGCCTC 0.928198 212 + >GENE_2 8 AAACCGTCTC 0.92009 170 + >GENE_4 3 TAACCGCCTC 0.918883 370 + ********** I am trying to count the unique() occurrence under each motif and add it to the MOTIF SUMMARY and a final average of them. My expected output is: MOTIFS SUMMARY: 1) TTATAGCCGC (GCGGCTATAA) 1.986 3 2) AAACCGCCTC (GAGGCGGTTT) 1.865 3 AVERAGE OCCURRENCE: 3 For motif 1, unique occurrence is 3 (GENE_1, GENE_2, GENE_3). Similarly for motif 2, it is again 3 (GENE_1, GENE_2, GENE_4) How can I use OCCURRENCES and ****** as blocks ? so that, I can regexp GENE_x to store it and count. Kindly help. Thanks, AP
You better try to change the original text file so that it will be legal matlab m file code, then just use 'eval' function to run it . Most of the job will be to find where to insert '=' and '[' ']' and '%' for ignore parts. If all files are identical in format than it will be easy.
String Concatenating functions in Progress 4GL?
I came across a function in C#, string.Join() which is really helpful for string concatenation. I am wondering is there any possibility of doing the same functionality in Progress 4GL ? Typical C# example would be, String result = “ ”; result = string.Join(",", this.grpBox1.Controls.OfType<CheckBox>() .Where(x => x.Checked) .Select(c => c.Text)); MessageBox.Show(result); I am not trying to convert C# to Progress but it would be really helpful if i could achieve the same functionality in Progress.
if you do really want your function you could wrap it and declare it as external you can re-link _progres to include your own c libs. used to be called HLC (probuild) but now its a set of scripts under a new directory name oebuild directly under the Progress install directory(DLC). The hlc and make directories are under the oebuild directory. Instructions on the build process can be found in the README file located in the oebuild directory under the DLC directory. Prob. a sledge hammer to crack a nut you would have to understand what your doing not for the faint of heart. but if you have something written in c you want to call you can do it. prob. best to stick to the 4gl nearest thing progress has to arrays is extent not used much most people break out to a temp table . rows in a tt are far easier to handle and iterate so its a "mind set" switch a bit. Important comments can also be found in the hlprodsp.c file located in the hlc directory, a subdirectory of oebuild.
As far as I know, there's nothing built in to that effort. But if I understand correctly, when you issue that command you get a list of that given object type (in your example, checkbox) as a CSV. I built something that resembles it, as a start to whatever you'd like to implement. It's probably far from perfect, but it works for me. It's a window with various widget types, you select from the combo the type you'd like to search and generate, and it will show you at the end the values of two CSV variables: one with the widget names that match that type, and one with the respective values. Here it goes: &Scoped-define WINDOW-NAME C-Win /*------------------------------------------------------------------------ File: Description: Input Parameters: <none> Output Parameters: <none> Author: Created: ------------------------------------------------------------------------*/ /* This .W file was created with the Progress AppBuilder. */ /*----------------------------------------------------------------------*/ /* Create an unnamed pool to store all the widgets created by this procedure. This is a good default which assures that this procedure's triggers and internal procedures will execute in this procedure's storage, and that proper cleanup will occur on deletion of the procedure. */ CREATE WIDGET-POOL. /* *************************** Definitions ************************** */ /* Parameters Definitions --- */ /* Local Variable Definitions --- */ DEFINE VARIABLE cWidgetLst AS CHARACTER NO-UNDO. DEFINE VARIABLE cValueLst AS CHARACTER NO-UNDO. /* ******************** Preprocessor Definitions ******************** */ &Scoped-define PROCEDURE-TYPE Window &Scoped-define DB-AWARE no /* Name of designated FRAME-NAME and/or first browse and/or first query */ &Scoped-define FRAME-NAME DEFAULT-FRAME /* Standard List Definitions */ &Scoped-Define ENABLED-OBJECTS COMBO-BOX-1 BUTTON-1 SLIDER-1 SELECT-1 ~ RADIO-SET-1 TOGGLE-1 FILL-IN-2 COMBO-BOX-3 &Scoped-Define DISPLAYED-OBJECTS COMBO-BOX-1 SLIDER-1 SELECT-1 RADIO-SET-1 ~ TOGGLE-1 FILL-IN-2 COMBO-BOX-3 /* Custom List Definitions */ /* List-1,List-2,List-3,List-4,List-5,List-6 */ /* *********************** Control Definitions ********************** */ /* Define the widget handle for the window */ DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO. /* Definitions of the field level widgets */ DEFINE BUTTON BUTTON-1 LABEL "Generate" SIZE 15 BY 1.14. DEFINE VARIABLE COMBO-BOX-1 AS CHARACTER FORMAT "X(256)":U VIEW-AS COMBO-BOX INNER-LINES 5 LIST-ITEMS "Fill-in","Radio-set","Toggle-box","Selection-List","slider","combo-box" DROP-DOWN-LIST SIZE 16 BY 1 NO-UNDO. DEFINE VARIABLE COMBO-BOX-3 AS CHARACTER FORMAT "X(256)":U LABEL "Combo 3" VIEW-AS COMBO-BOX INNER-LINES 5 LIST-ITEMS "Large","Tall","Venti" DROP-DOWN-LIST SIZE 16 BY 1 NO-UNDO. DEFINE VARIABLE FILL-IN-2 AS CHARACTER FORMAT "X(256)":U LABEL "Fill 2" VIEW-AS FILL-IN SIZE 14 BY 1 NO-UNDO. DEFINE VARIABLE RADIO-SET-1 AS INTEGER VIEW-AS RADIO-SET VERTICAL RADIO-BUTTONS "Item 1", 1, "Item 2", 2, "Item 3", 3 SIZE 12 BY 3 NO-UNDO. DEFINE VARIABLE SELECT-1 AS CHARACTER VIEW-AS SELECTION-LIST SINGLE SCROLLBAR-VERTICAL LIST-ITEMS "First","Second","Third" SIZE 23 BY 2 NO-UNDO. DEFINE VARIABLE SLIDER-1 AS INTEGER INITIAL 0 VIEW-AS SLIDER MIN-VALUE 0 MAX-VALUE 100 HORIZONTAL TIC-MARKS NONE SIZE 31 BY 2.38 NO-UNDO. DEFINE VARIABLE TOGGLE-1 AS LOGICAL INITIAL no LABEL "Toggle 1" VIEW-AS TOGGLE-BOX SIZE 13.4 BY .81 NO-UNDO. DEFINE VARIABLE COMBO-BOX-2 AS CHARACTER FORMAT "X(256)":U LABEL "Combo 2" VIEW-AS COMBO-BOX INNER-LINES 5 LIST-ITEMS "Item 1" DROP-DOWN-LIST SIZE 16 BY 1 NO-UNDO. DEFINE VARIABLE FILL-IN-3 AS CHARACTER FORMAT "X(256)":U LABEL "Fill 3" VIEW-AS FILL-IN SIZE 14 BY 1 NO-UNDO. DEFINE VARIABLE RADIO-SET-2 AS INTEGER VIEW-AS RADIO-SET VERTICAL RADIO-BUTTONS "Item 1", 1, "Item 2", 2, "Item 3", 3 SIZE 12 BY 3 NO-UNDO. DEFINE VARIABLE SLIDER-2 AS INTEGER INITIAL 0 VIEW-AS SLIDER MIN-VALUE 0 MAX-VALUE 100 HORIZONTAL TIC-MARKS NONE SIZE 17 BY 2.14 NO-UNDO. DEFINE VARIABLE TOGGLE-2 AS LOGICAL INITIAL no LABEL "Toggle 2" VIEW-AS TOGGLE-BOX SIZE 13.4 BY .81 NO-UNDO. /* ************************ Frame Definitions *********************** */ DEFINE FRAME DEFAULT-FRAME COMBO-BOX-1 AT ROW 1.95 COL 13 COLON-ALIGNED NO-LABEL WIDGET-ID 14 BUTTON-1 AT ROW 1.95 COL 32 WIDGET-ID 2 SLIDER-1 AT ROW 3.62 COL 42 NO-LABEL WIDGET-ID 18 SELECT-1 AT ROW 3.86 COL 10 NO-LABEL WIDGET-ID 16 RADIO-SET-1 AT ROW 6.24 COL 10 NO-LABEL WIDGET-ID 6 TOGGLE-1 AT ROW 6.24 COL 30 WIDGET-ID 10 FILL-IN-2 AT ROW 7.19 COL 28 COLON-ALIGNED WIDGET-ID 12 COMBO-BOX-3 AT ROW 7.29 COL 56 COLON-ALIGNED WIDGET-ID 20 WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY SIDE-LABELS NO-UNDERLINE THREE-D AT COL 1 ROW 1 SIZE 80 BY 16 WIDGET-ID 100. DEFINE FRAME FRAME-A TOGGLE-2 AT ROW 1.24 COL 51 WIDGET-ID 6 RADIO-SET-2 AT ROW 1.48 COL 3 NO-LABEL WIDGET-ID 2 FILL-IN-3 AT ROW 1.95 COL 25 COLON-ALIGNED WIDGET-ID 8 SLIDER-2 AT ROW 3.14 COL 46 NO-LABEL WIDGET-ID 12 COMBO-BOX-2 AT ROW 3.38 COL 24 COLON-ALIGNED WIDGET-ID 10 WITH 1 DOWN KEEP-TAB-ORDER OVERLAY SIDE-LABELS NO-UNDERLINE THREE-D AT COL 5 ROW 10.29 SIZE 72 BY 5.71 TITLE "Frame A" WIDGET-ID 200. /* *********************** Procedure Settings ************************ */ /* Settings for THIS-PROCEDURE Type: Window Allow: Basic,Browse,DB-Fields,Window,Query Other Settings: COMPILE */ /* ************************* Create Window ************************** */ IF SESSION:DISPLAY-TYPE = "GUI":U THEN CREATE WINDOW C-Win ASSIGN HIDDEN = YES TITLE = "<insert window title>" HEIGHT = 16 WIDTH = 80 MAX-HEIGHT = 16 MAX-WIDTH = 80 VIRTUAL-HEIGHT = 16 VIRTUAL-WIDTH = 80 RESIZE = yes SCROLL-BARS = no STATUS-AREA = no BGCOLOR = ? FGCOLOR = ? KEEP-FRAME-Z-ORDER = yes THREE-D = yes MESSAGE-AREA = no SENSITIVE = yes. ELSE {&WINDOW-NAME} = CURRENT-WINDOW. /* END WINDOW DEFINITION */ /* *********** Runtime Attributes and AppBuilder Settings *********** */ /* SETTINGS FOR WINDOW C-Win VISIBLE,,RUN-PERSISTENT */ /* REPARENT FRAME */ ASSIGN FRAME FRAME-A:FRAME = FRAME DEFAULT-FRAME:HANDLE. /* SETTINGS FOR FRAME DEFAULT-FRAME FRAME-NAME */ DEFINE VARIABLE XXTABVALXX AS LOGICAL NO-UNDO. ASSIGN XXTABVALXX = FRAME FRAME-A:MOVE-AFTER-TAB-ITEM (COMBO-BOX-3:HANDLE IN FRAME DEFAULT-FRAME) /* END-ASSIGN-TABS */. /* SETTINGS FOR FRAME FRAME-A */ IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win) THEN C-Win:HIDDEN = no. /* ************************ Control Triggers ************************ */ &Scoped-define SELF-NAME C-Win ON END-ERROR OF C-Win /* <insert window title> */ OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO: /* This case occurs when the user presses the "Esc" key. In a persistently run window, just ignore this. If we did not, the application would exit. */ IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY. END. ON WINDOW-CLOSE OF C-Win /* <insert window title> */ DO: /* This event will close the window and terminate the procedure. */ APPLY "CLOSE":U TO THIS-PROCEDURE. RETURN NO-APPLY. END. &Scoped-define SELF-NAME BUTTON-1 ON CHOOSE OF BUTTON-1 IN FRAME DEFAULT-FRAME /* Generate */ DO: assign cWidgetLst = '' cValueLst = ''. run downTheRabbitHole ( input {&window-name}:handle). MESSAGE cWidgetLst SKIP cValueLst VIEW-AS ALERT-BOX INFO BUTTONS OK. END. &UNDEFINE SELF-NAME /* *************************** Main Block *************************** */ /* Set CURRENT-WINDOW: this will parent dialog-boxes and frames. */ ASSIGN CURRENT-WINDOW = {&WINDOW-NAME} THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}. /* The CLOSE event can be used from inside or outside the procedure to */ /* terminate it. */ ON CLOSE OF THIS-PROCEDURE RUN disable_UI. /* Best default for GUI applications is... */ PAUSE 0 BEFORE-HIDE. /* Now enable the interface and wait for the exit condition. */ /* (NOTE: handle ERROR and END-KEY so cleanup code will always fire. */ MAIN-BLOCK: DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK: RUN enable_UI. IF NOT THIS-PROCEDURE:PERSISTENT THEN WAIT-FOR CLOSE OF THIS-PROCEDURE. END. /* ********************** Internal Procedures *********************** */ PROCEDURE buildCSV : /*------------------------------------------------------------------------------ Purpose: Parameters: <none> Notes: ------------------------------------------------------------------------------*/ DEFINE INPUT-OUTPUT PARAMETER iopcList AS CHARACTER NO-UNDO. DEFINE INPUT PARAMETER ipcValue AS CHARACTER NO-UNDO. if ipcValue = ? then assign ipcValue = '?'. if ipcValue = '' then assign ipcValue = ' '. assign iopcList = iopcList + (if iopcList = '' then '' else ',') + ipcValue. END PROCEDURE. PROCEDURE disable_UI : /*------------------------------------------------------------------------------ Purpose: DISABLE the User Interface Parameters: <none> Notes: Here we clean-up the user-interface by deleting dynamic widgets we have created and/or hide frames. This procedure is usually called when we are ready to "clean-up" after running. ------------------------------------------------------------------------------*/ /* Delete the WINDOW we created */ IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win) THEN DELETE WIDGET C-Win. IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE. END PROCEDURE. PROCEDURE downTheRabbitHole : /*------------------------------------------------------------------------------ Purpose: Parameters: <none> Notes: ------------------------------------------------------------------------------*/ DEFINE INPUT PARAMETER iphWidget AS HANDLE NO-UNDO. DEFINE VARIABLE hHandle AS HANDLE NO-UNDO. assign hHandle = iphWidget:first-child. do while valid-handle(hHandle): if can-query(hHandle,"type") and hHandle:type = combo-box-1:screen-value in frame {&frame-name} then do: /* something something something dark side... */ if can-query(hHandle,"name") then run buildCSV(input-output cWidgetLst,hHandle:name). if can-query(hHandle,"screen-value") then run buildCSV(input-output cValueLst,hHandle:screen-value). end. if hHandle:type = "FIELD-GROUP" or hHandle:type = "FRAME" then run downTheRabbitHole(input hHandle:first-child). assign hHandle = hHandle:next-sibling. end. END PROCEDURE. PROCEDURE enable_UI : /*------------------------------------------------------------------------------ Purpose: ENABLE the User Interface Parameters: <none> Notes: Here we display/view/enable the widgets in the user-interface. In addition, OPEN all queries associated with each FRAME and BROWSE. These statements here are based on the "Other Settings" section of the widget Property Sheets. ------------------------------------------------------------------------------*/ DISPLAY COMBO-BOX-1 SLIDER-1 SELECT-1 RADIO-SET-1 TOGGLE-1 FILL-IN-2 COMBO-BOX-3 WITH FRAME DEFAULT-FRAME IN WINDOW C-Win. ENABLE COMBO-BOX-1 BUTTON-1 SLIDER-1 SELECT-1 RADIO-SET-1 TOGGLE-1 FILL-IN-2 COMBO-BOX-3 WITH FRAME DEFAULT-FRAME IN WINDOW C-Win. {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME} DISPLAY TOGGLE-2 RADIO-SET-2 FILL-IN-3 SLIDER-2 COMBO-BOX-2 WITH FRAME FRAME-A IN WINDOW C-Win. ENABLE TOGGLE-2 RADIO-SET-2 FILL-IN-3 SLIDER-2 COMBO-BOX-2 WITH FRAME FRAME-A IN WINDOW C-Win. {&OPEN-BROWSERS-IN-QUERY-FRAME-A} VIEW C-Win. END PROCEDURE.
Change a setting on all the combo box objects on all the forms
tldr: How do I refer to each combo box, on each form, in turn? I discovered quite late in the game that the default for combo boxes is "LimitToList = False." This is very bad, because I have lots of combo boxes and no one should ever be adding or editing anything by typing over them. My users keep doing that, and I need them to stop. I already know how to, e.g., change all my forms so that the split form orientation is "datasheet on the bottom." That is, I've already solved the problem of "open all the forms, change a setting on each one, rinse, repeat." What I have works beautifully: 1 Public Sub MakeSplitFormsAllBottom() 2 3 Dim strForm As String, db As DAO.Database 4 Dim doc As DAO.Document 5 Set db = CurrentDb 6 7 For Each doc In db.Containers("Forms").Documents 8 9 strForm = doc.Name 10 11 DoCmd.OpenForm strForm, acDesign 12 Forms(strForm).SplitFormOrientation = 1 13 14 DoEvents 15 DoCmd.Close acForm, strForm, acSaveYes 16 17 Next doc 18 19 End Sub The trouble is that I can't quite figure out how to change a setting on all of the combo boxes on each of those forms. I Googled around quite a bit and didn't find any good examples, so I took a (bunch of) shots in the dark which generally look like this: 1 Public Sub MakeAllCombosLimited() 2 3 Dim strForm As String, db As DAO.Database, obj As AccessObject, strObj As String 4 Dim doc As DAO.Document 5 Set db = CurrentDb 6 7 For Each doc In db.Containers("Forms").Documents 8 9 strForm = doc.Name 10 11 DoCmd.OpenForm strForm, acDesign 12 13 For Each obj In strForm 14 Forms(strForm).Controls(obj).LimitToList = True 15 DoEvents 16 Next obj 17 18 DoEvents 19 DoCmd.Close acForm, strForm, acSaveYes 20 21 Next doc 22 23 End Sub Nothing I have tried has worked. The one above gives me the error "For Each may only iterate over a collection object or an array." I also tried variations of: 7 For Each obj in db.Containers("Forms").Documents To just refer to all the objects in the entire database, but that didn't work either - "Sub or Function not defined" is what I get, my guess that's because you need to say that the object belongs to a specific form. I'm not sure what questions I should be asking, to be honest. It seems to me that the bottom line is I need to know at least one of the following: How do I refer to/modify all the combo boxes in the entire database, or How do I refer to/modify all the combo boxes in a given form? But I know that I don't know the answer to either one. I feel like I'm making this harder than it needs to be.
Not sure if this will work in Access, but please try: Dim ctrl as Control For each ctrl in Form.Controls 'Revise to refer to your form object. If TypeOf(ctrl) Is MSForms.ComboBox 'Do something with the ctrl, here: ' ' End If Next
Here is the set of code that actually did what I wanted it to do: 1 Public Sub MakeAllCombosLimited() 2 3 Dim db As DAO.Database, strForm As String 4 Dim doc As DAO.Document 5 Set db = CurrentDb 6 7 For Each doc In db.Containers("Forms").Documents 8 strForm = doc.Name 9 DoCmd.OpenForm strForm, acDesign 10 11 For Each ctl In Forms(strForm).Controls 12 13 If ctl.ControlType = acComboBox Then 14 ctl.LimitToList = True 15 End If 16 17 Next ctl 18 19 DoEvents 20 DoCmd.Close acForm, strForm, acSaveYes
Creating open-high-low-close (ohlc) bars from tick data in Matlab
I have a CSV file 'XPQ12.csv' of futures tick data in the following form: 20090312 30:14.0 717.25 1 E 20090312 30:15.0 718.47 1 E 20090312 30:17.0 717.25 1 E 20090312 30:32.0 718.42 1 E 20090312 30:49.0 715.32 1 E 20090312 30:58.0 717.57 1 E 20090312 31:06.0 716.65 3 E 20090312 31:12.0 718.35 2 E 20090312 31:45.0 721.14 1 E 20090312 31:52.0 719.24 1 E 20090312 32:11.0 717.02 6 E 20090312 32:29.0 717.14 1 E 20090312 32:35.0 717.34 1 E 20090312 32:55.0 717.26 1 E (The first column is the yearmonthdate, the second column is the minute:second:tenthofsecond, the third column is the price, the fourth column is the number of contracts traded, and the fifth indicates if the trade was electronic or in a pit). In my actual data set, I may have thousands of price quotes within any given minute. I read the file using the following code: fid = fopen('C:\Program Files\MATLAB\R2013a\XPQ12.csv','r'); [c] = fscanf(fid, '%d,%d:%d.%d,%f,%d,%c') Which outputs: 20090312 30 14 0 717.25 1 69 20090312 30 15 0 718.47 3 69 . . . (the 69s are the matlab representation for E I believe) Now I want to cut this up into one minute ohlc bars, so that for each minute, I record what the first, highest, lowest, and last price was within that minute. I'd really like to know the best way to go about this. My original idea was to store the sequence of minutes in a vector d, and while working through the data, each time the number at the end of d changed I would record the corresponding price as an open, record the previous price as a close for the last bar, and find the largest and smallest prices within each open and close. c(2) is the first minute, so I said: d(1)=c(2); and then noting that I'd always be counting by 7 before getting to the next minute, I said: Nrows = numel(textread('XPQ12.csv','%1c%*[^\n]')); % counts rows in file for i=1:Nrows if mod(i-2,7)== 0; d(end+1)=c(i); end end which should fill up d with all the minutes: 30 30 30 30 30 30 31 31 31 31 32 32 32 32 in the case of the example data. I'm kind of lost what to do from here, or if what I'm doing is on the right track.
From where you are: Minutes = c(2:7:end); MinuteValues=unique(Minutes); Prices = c(5:7:end); if (length(Prices)>length(Minutes)) Prices=Prices(1:length(Minutes)); elseif (length(Prices)<length(Minutes)) Minutes=Minutes(1:length(Prices)); OverflowValues=1+find(Minutes(2:end)==0 & Minutes(1:end-1)==59); for v=length(OverflowValues):-1:1 Minutes(OverflowValues(v):end)=Minutes(OverflowValues(v):end)+60; end Highs=zeros(1,length(MinuteValues)); Lows=zeros(1,length(MinuteValues)); First=zeros(1,length(MinuteValues)); Last=zeros(1,length(MinuteValues)); for v=1:length(MinuteValues) Highs(v) = max(Prices(Minutes==MinuteValues(v))); Lows(v) = min(Prices(Minutes==MinuteValues(v))); First(v) = Prices(find(Minutes==MinuteVales(v),1,'first')); Last(v) = Prices(find(Minutes==MinuteVales(v),1,'last')); end Using textread would make this easier for you, as mentioned. (If you are lost at this stage, I wouldn't find accumarray as mentioned in the comments is the best place to start!) By the way, this is assuming that minutes increases above 60 and you don't have hours in there somewhere. Otherwise this won't work at all.