listbox and variable images

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Chris Vorster
Newbie
Posts: 3
Joined: Tue Aug 12, 2008 9:30 am
Location: South Africa

listbox and variable images

Post by Chris Vorster » Tue Aug 12, 2008 9:46 am

Hi, I am trying to create a dialog with a listbox containing items corresponding to differrent images, that I would like to display on the same dialog.

In other words, each time I choose a differrent item in the list, the image on the dialog box must update. I have tried to do this, but I am unfortunately not yet an expert with this software.

Could anyone please assist?

Here is what I've got so far:

Code: Select all

Let>shapec=%cwd%\20.jpg
Dialog>MyDialog
   Caption=Dialog1
   Width=445
   Height=289
   Top=253
   Left=187
   ListBox=msListBox1,8,8,89,241,20%CRLF%32%CRLF%33%CRLF%34
   Image=%shapec%,112,8,201,241,msImage1,0
   Button=OK,344,160,75,25,3
   Button=Cancel,344,200,75,25,2
   Button=Update,344,120,75,25,5
EndDialog>MyDialog

Let>shapec=%cwd%\20.jpg
Show>MyDialog

Label>ActionLoop

GetDialogAction>MyDialog,r

if>r=5,Update

if>r=6,Close

if>r=2,exit

Goto>ActionLoop

Label>exit

SRT>Update
If>MyDialog.msListbox1=20
Let>shapec=20.jpg
Let>MyDialog.msImage1=%cwd%\20.jpg

EndIf

If>MyDialog.msListbox1=32
Let>shapec=32.jpg
Let>MyDialog.msImage1=%cwd%\32.jpg

EndIf

END>Update

SRT>Close

  CloseDialog>MyDialog
  Let>r=2

END>Close

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

Post by JRL » Tue Aug 12, 2008 1:51 pm

You're close, you need to add ResetDialogAction>MyDialog to make the dialog refresh and show the last image selection. In the following sample your script is cleaned up a bit. Your Update subroutine is rewritten so that it will work with any number-named image up to 100. By changing the "ImageCount" variable the range could be greater or smaller.

It is good practice to NOT use single characters as variables. The practice will eventually get you into trouble. Therefore, the variable "r" is changed to "res".

Code: Select all

Let>shapec=%cwd%\20.jpg
Let>ImageCount=100

Dialog>MyDialog
   Caption=Dialog1
   Width=445
   Height=289
   Top=253
   Left=187
   ListBox=msListBox1,8,8,89,241,20%CRLF%32%CRLF%33%CRLF%34
   Image=%shapec%,112,8,201,241,msImage1,10
   Button=OK,344,160,75,25,3
   Button=Cancel,344,200,75,25,2
   Button=Update,344,120,75,25,5
EndDialog>MyDialog

Show>MyDialog

Label>ActionLoop
  GetDialogAction>MyDialog,res
  if>res=5,Update
  if>res=2,exit
Goto>ActionLoop

Label>exit

SRT>Update
  Let>kk=0
  Repeat>kk
    add>kk,1
    If>MyDialog.msListbox1=%kk%
      Let>MyDialog.msImage1=%cwd%\%kk%.jpg
      ResetDialogAction>MyDialog
    EndIf
  Until>kk,%ImageCount%
END>Update

Chris Vorster
Newbie
Posts: 3
Joined: Tue Aug 12, 2008 9:30 am
Location: South Africa

Post by Chris Vorster » Wed Aug 13, 2008 9:53 am

Great! Thanx, this helps alot. But if I removed the "Update" button, is it possible to have the images update automatically as I scroll through the list items?

The idea is to show matching pictures to list items, and then to press the OK button, which will call on a command related to that list item.

Thanx for your help, you guys are great!

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

Post by JRL » Wed Aug 13, 2008 2:22 pm

No Update Button.

Code: Select all

Let>shapec=%cwd%\20.jpg
Let>ImageCount=100
Let>CurrentImage=20

Dialog>MyDialog
   Caption=Dialog1
   Width=445
   Height=289
   Top=253
   Left=187
   ListBox=msListBox1,8,8,89,241,20%CRLF%32%CRLF%33%CRLF%34
   Image=%shapec%,112,8,201,241,msImage1,10
   Button=OK,344,160,75,25,3
   Button=Cancel,344,200,75,25,2
   //Button=Update,344,120,75,25,5
EndDialog>MyDialog

Show>MyDialog


Label>ActionLoop
  GetDialogAction>MyDialog,res
  //if>res=5,Update
  if>res=2,exit
  If>%MyDialog.msListbox1%<>%CurrentImage%,Update
Goto>ActionLoop

Label>exit

SRT>Update
  Let>kk=0
  Repeat>kk
    add>kk,1
    If>MyDialog.msListbox1=%kk%
      Let>MyDialog.msImage1=%cwd%\%kk%.jpg
      ResetDialogAction>MyDialog
      Let>CurrentImage=%kk%
    EndIf
  Until>kk,%ImageCount%
END>Update

Chris Vorster
Newbie
Posts: 3
Joined: Tue Aug 12, 2008 9:30 am
Location: South Africa

Post by Chris Vorster » Thu Aug 14, 2008 5:40 am

Thank you, you've been extremely helpful!

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