Pre-selecting multiple values in a multiselect list

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
jsarver1
Newbie
Posts: 5
Joined: Wed Jul 15, 2009 6:35 pm

Pre-selecting multiple values in a multiselect list

Post by jsarver1 » Wed Jul 15, 2009 6:44 pm

I have a multiselect list in a dialog that I want to preselect different values depending on what a user selects in a previous dialog. If I make the list not multiselect, then I can pre-select a single value based on the procedure using the itemindex statement mentioned in the manual. Once I make the list multiselect, however, I can no longer pre-select even a single value. This makes me think that my code is okay, except that I am not correctly stating how to pre-select from a multiselect list box. Thanks for any help that anyone may be able to offer on how to preselect mutliple values in a multiselect list.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jul 15, 2009 10:01 pm

Wow... not a typical "Beginners" question.

I went searching and found a library function. Hope this makes sense:

Code: Select all

Dialog>Dialog1
   Caption=Multiselect Test
   Width=215
   Height=356
   Top=100
   Left=CENTER
   ListBox=msListBox1,44,27,121,238,item1%CRLF%item2%CRLF%item3%CRLF%item4%CRLF%item5%CRLF%item6%CRLF%item7%CRLF%item8%CRLF%item9%CRLF%item10%CRLF%item11%CRLF%item12%CRLF%item13%CRLF%item14,true
   Button=OK,70,283,75,25,3
EndDialog>Dialog1

show>dialog1

Let>LB_SETSEL=389
//Run the following for each pre-chosen 0 based item selection
//The last number is the one to change 0 = the first item,
//3 = the fourth item, 5 = the sixth item, etc.
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,0
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,3
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,5
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,11
LibFunc>user32,SendMessageA,SMres,dialog1.msListBox1.handle,LB_SETSEL,1,12

Label>Loop
  GetDialogAction>dialog1,res1
  If>res1=2
    Exit>0
  EndIf
  If>res1=3
    GoSub>Process
  EndIf
  Wait>0.01
Goto>Loop

SRT>Process
  MDL>dialog1.msListBox1
  ResetDialogAction>Dialog1
END>Process

jsarver1
Newbie
Posts: 5
Joined: Wed Jul 15, 2009 6:35 pm

Is this right?

Post by jsarver1 » Thu Jul 16, 2009 12:16 am

JRL,

Thanks for the help. I am afraid that I was not able to follow all that you wrote. I tried taking a snippet of it and applying it to my specific case. I have a dialog (Picker) and a multiselect list (lab). I tried inserting this:

Let>LB_SETSEL=389
LibFunc>user32,SendMessageA,SMres,Picker.lab.handle,LB_SETSEL,1,0

But it did not seem to have an effect. I have xp pro x64, so I tried substituting 64 for 32 under the user32 part of the statement, but to no avail. I appreciate your help and your quick response to my earlier post.

Thanks,
---Josh

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Need to load library

Post by gdyvig » Thu Jul 16, 2009 1:16 am

Hi,

I think Dick forgot to include the LibLoad and LibFree commands which he probably executes elsewhere.

Code: Select all

//Load the library before doing and LibFuncs
LibLoad>user32,handle
//Do your LibFuncs
//Unload the library when done
LibFree>handle

I am assuming user32 is not automatically loaded, I don't see any documentation saying it is but I see lots of LibFunc code examples without the LibLoad/LibFree commands shown.

If my suggestion does not work, double-check your syntax, you made all the corresponding name changes, no embedded or trailing spaces exist, all of the % are there.

Gale

jsarver1
Newbie
Posts: 5
Joined: Wed Jul 15, 2009 6:35 pm

Post by jsarver1 » Thu Jul 16, 2009 2:08 am

Thanks for the help. Unfortunately, it is still not working. Using that method, I could pre-select if I made the listbox single selection, but it still did not provide a result if I made it multiselect. Here is the flawed code that I have:

Month>the_month
Day>the_day
Year>the_year
Hour>the_hour
Min>the_min

' Set the variables that are the same for all
Let>mytimetxt=%the_month%/%the_day%/%the_year% %the_hour%%the_min%

'Define the Picker dialog
Dialog>Picker
Caption=Select the items for a brief RME note
Width=800
Height=600
Top=106
Left=16
Edit=mytime,72,24,121,mytimetxt
ListBox=multistatement,8,64,225,87,Vital signs reviewed%CRLF%Patient examined%CRLF%No acute distress%CRLF%Minimal immediate risk of catastrophe%CRLF%Patient informed of RME process%CRLF%Patient will notify if condition change,true
Memo=HPI,8,184,226,177,
ListBox=EKG,112,376,121,76,Normal Sinus Rhythm%CRLF%Sinus tach%CRLF%Sinus brady%CRLF%Atrial fibrillation%CRLF%No STEMI,true
ListBox=lab,256,48,118,191,ABG%CRLF%CBC%CRLF%Chem 7%CRLF%Magnesium%CRLF%lipase%CRLF%LFTs%CRLF%PT/PTT%CRLF%AMI panel%CRLF%BNP%CRLF%D-dimer%CRLF%beta-HCG%CRLF%blood cultures%CRLF%UA%CRLF%urine cultures,true
ListBox=imaging,256,272,116,184,Xray chest%CRLF%Xray for fracture%CRLF%Xray foreign body%CRLF%CT head%CRLF%CT abd/pelvis%CRLF%CT PE%CRLF%CT aorta%CRLF%MRI head%CRLF%MRI back%CRLF%Ultrasound abdomen%CRLF%Ultrasound appendix%CRLF%Ultrasound pelvis%CRLF%Ultrasound DVT,true
ListBox=RMEmeds,400,48,121,97,RMEmedtxt,true
ListBox=meds,400,184,121,157,medstxt,true
Label=Contact time,8,24,true
ListBox=diffdx,536,56,121,189,diffdxtxt,true
Label=General,8,48,true
RadioGroup=radiodispo,Area to be roomed,544,248,107,57,ED 1%CRLF%ED 2%CRLF%ED 3,-1
RadioGroup=radiocourse,Likely ED course,536,320,185,94,coursetxt,-1
Button=&Preview Note,544,424,75,25,2
Button=&Cancel,624,424,75,25,3
Label=Labs ordered,256,32,true
ListBox=nursing,400,360,121,97,IV%CRLF%supplemental oxygen%CRLF%cardiac monitor%CRLF%pulse oxymetry%CRLF%EKG%CRLF%breathing treatment%CRLF%LET to wound,true
Label=Nursing orders,408,344,true
Label=Imaging,256,256,true
Label=Brief HPI,8,168,true
Label=Meds to be given in RME,392,32,true
Label=Meds when roomed,400,160,true
Label=Most likely diagnoses,544,32,true
Label=Brief EKG review:,16,376,true
EndDialog>Picker

' Close the template dialog
CloseDialog>template
//Load the library before doing and LibFuncs
LibLoad>user32,handle

//determine which values to preselect and which lists to generate based
//on previous dialog (template) and field (complaint)
if>template.complaint=general

Let>LB_SETSEL=389
LibFunc>user32,SendMessageA,SMres,Picker.lab.handle,LB_SETSEL,1,1
LibFunc>user32,SendMessageA,SMres,Picker.lab.handle,LB_SETSEL,1,3
Let>RMEmedtxt=Vicodin%CRLF%Zofran ODT%CRLF%Aspirin 162mg PO x1%CRLF%LET to wound%CRLF%EMLA for IV/LP%CRLF%Tetanus%CRLF%Azithromycin 500mg po
Let>medstxt=NS 500mL IV%CRLF%NS 1L IV%CRLF%NS 2L IV%CRLF%NS 20ml/KG IV x 2%CRLF%Morphine 4mg IV%CRLF%Dilaudid 1mg IV%CRLF%Zofran 4mg IV%CRLF%Reglan 10mg IV%CRLF%Ceftriaxone 1g IV
Let>diffdxtxt=[enter likely diagnosis on preview page]
Let>coursetxt=Admit after workup%CRLF%Admit now%CRLF%Discharge after workup%CRLF%Discharge after workup/pain control
endif

'Show the Picker dialog
Show>Picker,p

//Unload the library when done
LibFree>handle

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jul 16, 2009 4:27 am

Josh,

There's a couple of related items.

1) The libfunc calls have to occur while the dialog is open.
2) That means you have to use a non-modal dialog rather than what you have which is a modal dialog.

A modal dialog stops the script until the user makes a selection, a non-modal dialog allows the script to continue running and performing actions while the user makes or doesn't make selections. The primary difference in the creation of a modal dialog or a non-modal dialog is whether or not the dialog result variable is placed on the Show>dialog line. See "dialog" help for more information.

I've rewritten your snippet. The changes I made are:

- moved the Show>Picker line to be ahead of the libfunc>
- removed the "p" variable from the Show>Picker line.
- added the "ActionLoop" to handle the non-modal dialog results.
- also remarked out the if>template.complaint=general test line just because it was easier than making the statement resolve to true. Be sure to unremark that line and the associated "Endif" line when you put this back into you main script.

Gale,

I've never used anything but the libfunc on any of the standard windows library files. I think any dll that would show up when you run "tasklist /m" is already loaded. In any case, LibLoad and Libfree don't seem to hurt anything but I'm certain they're not necessary for user32, kernel32 or GDI32. Those are about the only ones I ever use. No... I also use Marcus' GetClient.dll successfully without a libload. Makes me wonder what circumstance actually requires libload/libfree.

Code: Select all

Month>the_month
Day>the_day
Year>the_year
Hour>the_hour
Min>the_min

' Set the variables that are the same for all
Let>mytimetxt=%the_month%/%the_day%/%the_year% %the_hour%%the_min%

'Define the Picker dialog
Dialog>Picker
Caption=Select the items for a brief RME note
Width=800
Height=600
Top=106
Left=16
Edit=mytime,72,24,121,mytimetxt
ListBox=multistatement,8,64,225,87,Vital signs reviewed%CRLF%Patient examined%CRLF%No acute distress%CRLF%Minimal immediate risk of catastrophe%CRLF%Patient informed of RME process%CRLF%Patient will notify if condition change,true
Memo=HPI,8,184,226,177,
ListBox=EKG,112,376,121,76,Normal Sinus Rhythm%CRLF%Sinus tach%CRLF%Sinus brady%CRLF%Atrial fibrillation%CRLF%No STEMI,true
ListBox=lab,256,48,118,191,ABG%CRLF%CBC%CRLF%Chem 7%CRLF%Magnesium%CRLF%lipase%CRLF%LFTs%CRLF%PT/PTT%CRLF%AMI panel%CRLF%BNP%CRLF%D-dimer%CRLF%beta-HCG%CRLF%blood cultures%CRLF%UA%CRLF%urine cultures,true
ListBox=imaging,256,272,116,184,Xray chest%CRLF%Xray for fracture%CRLF%Xray foreign body%CRLF%CT head%CRLF%CT abd/pelvis%CRLF%CT PE%CRLF%CT aorta%CRLF%MRI head%CRLF%MRI back%CRLF%Ultrasound abdomen%CRLF%Ultrasound appendix%CRLF%Ultrasound pelvis%CRLF%Ultrasound DVT,true
ListBox=RMEmeds,400,48,121,97,RMEmedtxt,true
ListBox=meds,400,184,121,157,medstxt,true
Label=Contact time,8,24,true
ListBox=diffdx,536,56,121,189,diffdxtxt,true
Label=General,8,48,true
RadioGroup=radiodispo,Area to be roomed,544,248,107,57,ED 1%CRLF%ED 2%CRLF%ED 3,-1
RadioGroup=radiocourse,Likely ED course,536,320,185,94,coursetxt,-1
Button=&Preview Note,544,424,75,25,2
Button=&Cancel,624,424,75,25,3
Label=Labs ordered,256,32,true
ListBox=nursing,400,360,121,97,IV%CRLF%supplemental oxygen%CRLF%cardiac monitor%CRLF%pulse oxymetry%CRLF%EKG%CRLF%breathing treatment%CRLF%LET to wound,true
Label=Nursing orders,408,344,true
Label=Imaging,256,256,true
Label=Brief HPI,8,168,true
Label=Meds to be given in RME,392,32,true
Label=Meds when roomed,400,160,true
Label=Most likely diagnoses,544,32,true
Label=Brief EKG review:,16,376,true
EndDialog>Picker

' Close the template dialog
CloseDialog>template
//Load the library before doing and LibFuncs
LibLoad>user32,handle

'Show the Picker dialog
Show>Picker

//determine which values to preselect and which lists to generate based
//on previous dialog (template) and field (complaint)

//if>template.complaint=general

Let>LB_SETSEL=389
LibFunc>user32,SendMessageA,SMres,Picker.lab.handle,LB_SETSEL,1,1
LibFunc>user32,SendMessageA,SMres,Picker.lab.handle,LB_SETSEL,1,3
Let>RMEmedtxt=Vicodin%CRLF%Zofran ODT%CRLF%Aspirin 162mg PO x1%CRLF%LET to wound%CRLF%EMLA for IV/LP%CRLF%Tetanus%CRLF%Azithromycin 500mg po
Let>medstxt=NS 500mL IV%CRLF%NS 1L IV%CRLF%NS 2L IV%CRLF%NS 20ml/KG IV x 2%CRLF%Morphine 4mg IV%CRLF%Dilaudid 1mg IV%CRLF%Zofran 4mg IV%CRLF%Reglan 10mg IV%CRLF%Ceftriaxone 1g IV
Let>diffdxtxt=[enter likely diagnosis on preview page]
Let>coursetxt=Admit after workup%CRLF%Admit now%CRLF%Discharge after workup%CRLF%Discharge after workup/pain control
//endif

Label>ActionLoop
  GetDialogAction>Picker,p
  If>p=2
    Exit>0
  EndIf
  If>p<>0,Continue
Goto>ActionLoop
Label>Continue
ResetDialogAction>Picker

//Unload the library when done
LibFree>handle

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

When libload/libfree are needed.

Post by gdyvig » Fri Jul 17, 2009 3:33 am

JRL wrote
Makes me wonder what circumstance actually requires libload/libfree.
I checked the manual. LibLoad/LibFree are not required unless you want to refer to the handle for subsequent LibFunc calls. This way Macro Scheduler would not need to re-load the library for each call. Maybe faster.

So they are not needed in Josh's script since he is not using the handle. Sorry about the false suggestion.



Gale

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jul 17, 2009 4:51 am

Gale,
Thanks for looking that up and posting the clarification. Perhaps, if it is faster, this would be a good place to use libload/libfree. If the listbox is long with lots of pre-selected items there could be many lines of nearly the exact libfunc> call. This might be the ideal application to use the handle instead.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts