Refresh Combo box in a dialog after modification

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Refresh Combo box in a dialog after modification

Post by mightycpa » Sun Mar 08, 2009 11:09 pm

Hi,

I've got a dialog box that contains a Combo box. The Combo box gets its values from an INI file, and I wanted to build a tab where I can add values to the list in the INI file. So far, so good, the macro can do that.

The next thing that I want to do is to display the new list in the combo box after the ADD.

I'm not having any luck. If I don't close the dialog, the combo box is never refreshed. If I close the dialog, and then re-open it, then the result depends on how I try to re-open it:

if the Create Dialog block is re-run as part of the restart, I get a nondescript error, it probably is complaining about the Dialog1 object already having been created.

if the Create Dialog block is skipped, and I just try to Show> again, then the combo boxes don't include the new values.

Line 42, MessageModal, seems to point to the problem. What can I do?

Tx,

George

Here's some abbreviated code to set it up:

To run the following code, you need a file, c:\ftploader.ini
and in it, you need this:

Code: Select all

[Clients]
//separate clients with pound sign #
clientlist=apple#baker#charlie

Then, here is MS code:

Code: Select all

VAREXPLICIT=0

//Initialize Variables
Let>delmsg= 

// move this create dialog block to immediately after SHOW, 
//     and you get a different error
Dialog>Dialog1
   Caption=Refresh a combo box
   Width=545
   Height=210
   Top=156
   Left=28
   TabBook=mytabs,32,10,20,15,1

   TabPage=Send File
     Label=Choose a name,32,26
     ComboBox=Client_list,32,40,200,clist

   TabPage=Download Client Files
     Label=Use the url below to download client files,32,8
     Label=http://url.com/files,32,40
	
   TabPage=Add Name
     Label=Use this tab to add a name to the dropdown box,32,8
     Label=Enter a client name,32,26
	 Edit=msEdit4,32,40,200,
     Label=Review the client list,32,74
     ComboBox=Clients4,32,90,200,clist
     Button=Add,244,40,75,25,4

   EndTabBook

EndDialog>Dialog1

Label>DialogStart
Let>clist1= 
ReadIniFile>c:\ftploader.ini,Clients,clientlist,clist0
StringReplace>clist0,#,%CRLF%,clist
MessageModal>clist


Show>Dialog1

Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=3,Send
if>r=4,Add
if>r=5,Edit
if>r=6,Delete
if>r=2,xit
if>r=99,Restart
Goto>ActionLoop

Label>xit
exit>

SRT>Restart
  CloseDialog>Dialog1
  Wait>5
  Goto>DialogStart
END>Restart  

SRT>Send

  ResetDialogAction>Dialog1
END>Send

SRT>Add
  StringReplace>%Dialog1.msEdit4%, ,,new_item
  If>Length(%new_item%)=0
    ResetDialogAction>Dialog1
  Endif>
  Concat>clist0,#
  Concat>clist0,%Dialog1.msEdit4%
  'MessageModal>clist0
  EditIniFile>c:\ftploader.ini,Clients,clientlist,clist0
  Let>r=99
END>Add

"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Post by JRL » Mon Mar 09, 2009 4:40 am

Added a couple of lines:
Concat>DIALOG1.CLIENTS4.ITEMS.TEXT,%Dialog1.msEdit4%
Concat>DIALOG1.CLIENT_LIST.ITEMS.TEXT,%Dialog1.msEdit4%

And a ResetDialogAction> to make them "reset" into the dialog.

If you step through this in the editor and watch the Watch List you can see these variables being created. Then you'll also know which variables need to be appended to. The ResetDialogAction> is nearly always a necessity to make changes show up in the dialog. One exception that I can think of is if you redo a label, a GetDialogAction> will also make it change in the dialog display.

Code: Select all

VAREXPLICIT=0

//Initialize Variables
Let>delmsg=

// move this create dialog block to immediately after SHOW, 
//     and you get a different error
Dialog>Dialog1
   Caption=Refresh a combo box
   Width=545
   Height=210
   Top=156
   Left=28
   TabBook=mytabs,32,10,20,15,1

   TabPage=Send File
     Label=Choose a name,32,26
     ComboBox=Client_list,32,40,200,clist

   TabPage=Download Client Files
     Label=Use the url below to download client files,32,8
     Label=http://url.com/files,32,40
    
   TabPage=Add Name
     Label=Use this tab to add a name to the dropdown box,32,8
     Label=Enter a client name,32,26
     Edit=msEdit4,32,40,200,
     Label=Review the client list,32,74
     ComboBox=Clients4,32,90,200,clist
     Button=Add,244,40,75,25,4

   EndTabBook

EndDialog>Dialog1

Label>DialogStart
Let>clist1=
ReadIniFile>c:\ftploader.ini,Clients,clientlist,clist0
Let>clist0=apple#baker#charlie
StringReplace>clist0,#,%CRLF%,clist
MessageModal>clist


Show>Dialog1

Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=3,Send
if>r=4,Add
if>r=5,Edit
if>r=6,Delete
if>r=2,xit
if>r=99,Restart
Goto>ActionLoop

Label>xit
exit>

SRT>Restart
  CloseDialog>Dialog1
  Wait>5
  Goto>DialogStart
END>Restart

SRT>Send

  ResetDialogAction>Dialog1
END>Send

SRT>Add
  StringReplace>%Dialog1.msEdit4%, ,,new_item
  If>Length(%new_item%)=0
    ResetDialogAction>Dialog1
  Endif>
  Concat>clist0,#
  Concat>clist0,%Dialog1.msEdit4%
  Concat>DIALOG1.CLIENTS4.ITEMS.TEXT,%Dialog1.msEdit4%
  Concat>DIALOG1.CLIENT_LIST.ITEMS.TEXT,%Dialog1.msEdit4%
  MessageModal>clist0
  EditIniFile>c:\ftploader.ini,Clients,clientlist,clist0
  ResetDialogAction>Dialog1
END>Add

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Mon Mar 09, 2009 6:29 am

Wow,

You really ARE the Automation Wizard!

So the CONCAT> lines are used to update the actual combo list contents, and the ResetDialogAction is akin to a RECREATE Dialog it seems.

I like that, thanks!

The other thing you mention, changing a label value, I'm not having much luck with that.

I made slight changes to the updated script:
I initialize a variable, mymsg=aaa
I add a Label to the right of the Add button, displays mymsg
On first pass, you see the label aaa
During the ADD sequence, I set mymsg = zzz
I also reset the Editbox = blank
Everything changes, except the label remains aaa

Ultimately, I want to add a message like "x record(s) added", so that the user gets a little feedback. I would start out where mymsg = blank space, so you can't see it first pass, and then manipulate it after each ADD. But I can't make the simple case work.

Can you push me over the edge here?

Tx,

George

Code: Select all


VAREXPLICIT=0

//Initialize Variables

//added here

Let>mymsg=aaa 

// move this create dialog block to immediately after SHOW, 
//     and you get a different error
Dialog>Dialog1
   Caption=Refresh a combo box
   Width=545
   Height=210
   Top=156
   Left=28
   TabBook=mytabs,32,10,20,15,1

   TabPage=Send File
     Label=Choose a name,32,26
     ComboBox=Client_list,32,40,200,clist

   TabPage=Download Client Files
     Label=Use the url below to download client files,32,8
     Label=http://url.com/files,32,40
	
   TabPage=Add Name
     Label=Use this tab to add a name to the dropdown box,32,8
     Label=Enter a client name,32,26
	 Edit=msEdit4,32,40,200,
     Label=Review the client list,32,74
     ComboBox=Clients4,32,90,200,clist
     Button=Add,244,40,75,25,4

//added here

     Label=mymsg,372,40

   EndTabBook

EndDialog>Dialog1

Label>DialogStart
Let>clist1= 
ReadIniFile>c:\ftploader.ini,Clients,clientlist,clist0
StringReplace>clist0,#,%CRLF%,clist


Show>Dialog1

Label>ActionLoop
GetDialogAction>Dialog1,r
if>r=3,Send
if>r=4,Add
if>r=5,Edit
if>r=6,Delete
if>r=2,xit
if>r=99,Restart
Goto>ActionLoop

Label>xit
exit>

SRT>Send

  ResetDialogAction>Dialog1
END>Send

SRT>Add
  StringReplace>%Dialog1.msEdit4%, ,,new_item
  If>Length(%new_item%)=0
    ResetDialogAction>Dialog1
  Endif>
  Concat>clist0,#
  Concat>clist0,%Dialog1.msEdit4%
  Concat>DIALOG1.CLIENTS4.ITEMS.TEXT,%Dialog1.msEdit4%
  Concat>DIALOG1.CLIENT_LIST.ITEMS.TEXT,%Dialog1.msEdit4%
  Let>Dialog1.msEdit4=
  'MessageModal>clist0
  EditIniFile>c:\ftploader.ini,Clients,clientlist,clist0
  'Let>r=99

// added here

  Let>mymsg=zzz
  'MessageModal>%mymsg%
  'Wait>3
  ResetDialogAction>Dialog1
END>Add
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Post by JRL » Mon Mar 09, 2009 2:05 pm

Same principle as the combo box variables. The dialog variables are created by the software not by you. The variable "mymsg" can be used one time to pass a value to be used in the original creation of the dialog. But after that creation moment, you have to use the variables that Macro Scheduler creates for the dialog.

In this case the variable you want to change is "dialog1.mslabel7".

Please note that as you work on your dialog the position of the objects in the dialog determines the number at the end of the variable name. So if you add or delete a label that shows up above the label whose value you're modifying, the name of the variable you're modifying will change.

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Mon Mar 09, 2009 2:27 pm

AHA!

"the position of the objects in the dialog determines the number at the end of the variable name"

How in the world did you figure that out?

Glad you're here to help... if I can figure out how to vote, you'll get some reputation points.

Thanks again.

George
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Mon Mar 09, 2009 2:29 pm

DEBUG variables!... oh, I've got to pay attention better.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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

Post by JRL » Mon Mar 09, 2009 3:28 pm

The "Watch List" has to be up there as one of the most useful tools ever invented!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Mar 10, 2009 12:35 am

if I can figure out how to vote, you'll get some reputation points.
Look at the bottom of each posting and look for this message.
Did this message help you? If so please reward the poster with Reputation Points? Reward Points
Go to the one that you want to reward and click there on reward points.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Post by mightycpa » Tue Mar 10, 2009 1:47 pm

yeah, awarding points wasn't nearly as difficult as getting those values to refresh...

thanks
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

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