Variables in a dialog

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
yken
Newbie
Posts: 17
Joined: Thu Jan 18, 2007 3:42 pm
Location: Turkiye

Variables in a dialog

Post by yken » Sat Apr 21, 2007 7:07 am

Hi!
Could you please tell me, how can I show my variables in a dialog box? If input 2, in the dialog box, I want to see first, adres0 and city0 and secondly adres1 and city1 and thirdly adres3 and city3 . In addition, "Error trying to create dialog:MyDialog" message appears each time.

Code: Select all

input>count,how many?
if>count=,end
let>k=0
repeat>k

let>adres=John Street%k%
let>city=London%k%
Wait>0.05
PutClipBoard>adres
let>adres%k%=adres
let>adres=
Wait>0.05
PutClipBoard>city
let>city%k%=city
let>city=
Wait>0.05
let>k=k+1
until>k,count

//SetFocus>Microsoft Excel - *
let>z=0
repeat>z
Wait>0.05

Dialog>MyDialog
   Width=450
   Height=200
   Top=500
   Left=200
   Label=%adres%%z%,50,50
   Label=%city%%z%,50,70
   Button=YES,14,5,165,20,3
   Button=NO,225,5,165,20,2
EndDialog>MyDialog

Show>MyDialog,result

Label>MainLoop
  If>result=2,End
  If>result=3,Write
Goto>MainLoop


label>Write
send>adres%z%
Wait>0.05
press tab
Wait>0.05
send>city%z%
Wait>0.05
press down
Wait>0.05
press left
Wait>0.05
let>z=z+1
until>z,count

Label>End

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Apr 21, 2007 11:03 am

Hi,

1st, the Dialog/EndDialog block CREATES a dialog. You can't create a dialog that has already been created. So your Dialog block should only appear once. So take it outside the loop.

2nd, if you want to CHANGE values on a dialog (as opposed to initialise them) you will need to set the object values and use ResetDialogAction after using the Show command.

So the following code will work for you:

Code: Select all

input>count,how many?
if>count=,end
let>k=0
repeat>k

let>adres=John Street%k%
let>city=London%k%
Wait>0.05
PutClipBoard>adres
let>adres%k%=adres
let>adres=
Wait>0.05
PutClipBoard>city
let>city%k%=city
let>city=
Wait>0.05
let>k=k+1
until>k,count

Dialog>MyDialog
   Width=450
   Height=200
   Top=500
   Left=200
   Label=,50,50
   Label=,50,70
   Button=YES,14,5,165,20,3
   Button=NO,225,5,165,20,2
EndDialog>MyDialog

//SetFocus>Microsoft Excel - *
let>z=0
repeat>z
Wait>0.05

Show>MyDialog
Let>this_adr=adres%z%
Let>this_cty=city%z%
Let>MyDialog.msLabel0=%this_adr%
Let>MyDialog.msLabel1=%this_cty%
ResetDialogAction>MyDialog
CloseDialog>MyDialog
Show>MyDialog,result

Label>MainLoop
  If>result=2,End
  If>result=3,Write
Goto>MainLoop


label>Write
send>adres%z%
Wait>0.05
press tab
Wait>0.05
send>city%z%
Wait>0.05
press down
Wait>0.05
press left
Wait>0.05
let>z=z+1
until>z,count

Label>End
The dialog block is created once. Then in each loop the dialog is Shown (to initialise it) and then the values are modified with ResetDialogAction. Then, because you want the dialog to be modal, we close the dialog and reopen it modal. Note that in Windows close actually just hides a window - it does not destroy it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

yken
Newbie
Posts: 17
Joined: Thu Jan 18, 2007 3:42 pm
Location: Turkiye

Thanks

Post by yken » Sat Apr 21, 2007 2:24 pm

Thank you for your answer. When I want to edit my code in the Dialog Designer, I don't see the name "msLabel0" and "msLabel1" when I push "F11". But I see the buttons names like "Button1" and "Button2". Thanks again.

Yken

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Apr 21, 2007 2:47 pm

Put cursor on first line and hit F8. Press F8 to step from line to line. You will see the object variables being created as you step over the dialog block. You'll see the msLabel variables etc.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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