Text from an array to populate a list box?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Text from an array to populate a list box?

Post by strosfan47 » Tue Feb 15, 2011 6:57 pm

I've been hammering on the V12 documentation hard, trying to unravel the mystery of how to execute the following SetDialogProperty at run time. Namely:
(Re: ListBox Text Property)"When assigning a list of items at run time using SetDialogProperty delimit lines with the %CRLF% variable."
Can somebody please fire me a quick example? In my ListBox I'd like to delimit/populate the Text property from an array, if possible. How would I typically use the %CRLF% in my SetDialogProperty statement?

Perhaps there's another approach I'm overlooking?

Thanks a million!
-- Bopert in Austin

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Tue Feb 15, 2011 9:15 pm

Here is some actual code from one of my dialogs.
This creates a list of possible actions in lbAction.

Code: Select all

Let>ACTIONS1=Click Button%CRLF%Rt Click Button%CRLF%Click Point%CRLF%Enter Text%CRLF%Menu Item%CRLF%Press Key%CRLF%Pause%CRLF%Mouse Move%CRLF%UserVar%CRLF%
Let>ACTIONS2=LAYOUT - Start%CRLF%LAYOUT - Kill%CRLF%LAYOUT - Set Focus%CRLF%MAKE - Start%CRLF%MAKE - Kill%CRLF%MAKE - Set Focus
SetDialogProperty>ScriptBuilder,lbAction,Text,%ACTIONS1%%ACTIONS2%
Thanks,
Jerry

[email protected]

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

inconsistent LlistBox behavior

Post by strosfan47 » Wed Feb 16, 2011 1:37 am

Thanks Jerry. Your suggestions sparked some ideas, but unfortunately, after much brain-wracking, I cannot get the desired behavior which is a selectable list of file names to populate a list box. Both ListBoxes have identical property settings.

Here's my code. It REQUIRES A DIRECTORY c:\anyDIR\ FILLED WITH AT LEAST ONE FILE to function.

Any more suggestions/tips?

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1

//THIS SAMPLE REQUIRES DIRECTORY c:\anyDIR\ FILLED W AT LEAST ONE FILE

//  THIS SAMPLE SHOWS HOW MSListBox2 (populated w array of file names and %CRLF% ) 
//  BEHAVES DIFFERENTLY THAN MSListBox1 (populated w static string data and %CRLF%) AS
//  THE FORMER APPARENTLY CANNOT RETAIN ITS MULTI-SELECT CAPABILTIES  

//dialog box w two ListBoxes and one CheckBox
Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 94
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Source File Dialog Box'
  ClientHeight = 518
  ClientWidth = 710
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poDesigned
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton2: tMSButton
    Left = 319
    Top = 463
    Width = 75
    Height = 25
    Caption = 'Close'
    DoubleBuffered = True
    ModalResult = 2
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSListBox1: tMSListBox
    Left = 21
    Top = 24
    Width = 244
    Height = 425
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 1
    SelectedIndex = -1
  end
  object CheckBoxMOD: TCheckBox
    Left = 306
    Top = 118
    Width = 127
    Height = 17
    Caption = 'Modify'
    TabOrder = 2
  end
  object MSListBox2: tMSListBox
    Left = 469
    Top = 25
    Width = 212
    Height = 448
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 3
    SelectedIndex = -1
  end
  object MainMenu: tMSMainMenu
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -12
    Font.Name = 'Segoe UI'
    Font.Style = []
    object MenuItem1: tMSMenuItem
      Caption = 'File'
      object MenuItem2: tMSMenuItem
        Caption = 'New'
      end
      object MenuItem3: tMSMenuItem
        Caption = 'Open'
      end
      object MenuItem4: tMSMenuItem
        Caption = 'Save'
      end
    end
    object MenuItem5: tMSMenuItem
      Caption = 'Edit'
      object MenuItem6: tMSMenuItem
        Caption = 'Cut'
      end
      object MenuItem7: tMSMenuItem
        Caption = 'Copy'
      end
      object MenuItem8: tMSMenuItem
        Caption = 'Paste'
      end
      object MenuItem9: tMSMenuItem
        Caption = '-'
      end
      object MenuItem10: tMSMenuItem
        Caption = 'Submenu'
        object MenuItem11: tMSMenuItem
          Caption = 'Item 1'
        end
        object MenuItem12: tMSMenuItem
          Caption = 'Item 2'
          object MenuItem13: tMSMenuItem
            Caption = '- Sub Item 1'
          end
          object MenuItem14: tMSMenuItem
            Caption = '- Sub Item 2'
          end
        end
        object MenuItem15: tMSMenuItem
          Caption = 'Item 3'
        end
        object MenuItem16: tMSMenuItem
          Caption = '-'
        end
      end
      object MenuItem17: tMSMenuItem
        Caption = 'Search'
      end
      object MenuItem18: tMSMenuItem
        Caption = 'Replace'
      end
    end
    object MenuItem19: tMSMenuItem
      Caption = 'Help'
      object MenuItem20: tMSMenuItem
        Caption = 'Contents'
      end
      object MenuItem21: tMSMenuItem
        Caption = '-'
      end
      object MenuItem22: tMSMenuItem
        Caption = 'About'
      end
    end
  end
end
EndDialog>Dialog1

//on CheckBoxMOD click, do SRT DoMODFiles that alters MSListBox2
AddDialogHandler>Dialog1,CheckBoxMOD,OnClick,DoMODFiles

//user JERRY suggestion on how to utilize %CRLF% in SetDialogProperty command
//and it works as it creates a list of multi-selectable items within MSListBox1
Let>ACTIONS1=Click Button%CRLF%Rt Click Button%CRLF%Click Point%CRLF%Enter Text%CRLF%
Let>ACTIONS2=LAYOUT - Start%CRLF%LAYOUT - Kill
SetDialogProperty>Dialog1,MSListBox1,Text,%ACTIONS1%%ACTIONS2%

Show>Dialog1,result
MessageModal>Why didn't MSListBox2 behave the same as MSListBox1?  The app needs a selectable list of file names...


SRT>DoMODFiles
//Go to specified dir & grab file data, populate array MOD_file_names(one at a time) w values
GetFileList>c:\anyDIR\*.*,files
Separate>files,;,MOD_file_names
//shows *.* file count
MessageModal>Num Files: %MOD_file_names_count%

Let>k=0
Repeat>k
         Let>k=k+1

//update property Text with value of MOD_file_names array, one at a time, then %CRLF%
SetDialogProperty>Dialog1,MSListBox2,Text,MOD_file_names_%k%
wait>.3
SetDialogProperty>Dialog1,MSListBox2,Text,%CRLF%

Until>k,MOD_file_names_count
wait>3

END>DoMODFiles



-- Bopert in Austin

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

Post by Marcus Tettmar » Wed Feb 16, 2011 8:24 am

Your code is only setting the list to one file each time and each iteration of the loop replaces the list with the next file. Doing it your way you would need to grow a variable by appending the filename to it and then set this to the list text *after* the loop.

However, all this looping is unnecessary. The following is all you need:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 449
  Top = 266
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 0
    Top = 0
    Width = 431
    Height = 212
    Align = alClient
    ItemHeight = 13
    TabOrder = 8
    SelectedIndex = -1
    ExplicitLeft = 22
    ExplicitTop = 12
    ExplicitWidth = 275
    ExplicitHeight = 97
  end
end
EndDialog>Dialog1

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF
SetDialogProperty>Dialog1,MSListBox1,Text,theList

Show>Dialog1,r
Note just two lines to retrieve the file list and populate the list box with 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?

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Post by strosfan47 » Wed Feb 16, 2011 2:58 pm

Marcus -- thanks for your quick reply and invaluable tip. The ",CRLF" suffix on the

Code: Select all

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF

command solved the CarriageReturn/LineFeed issue. Many thanks!

And you were right, removing the loop made the code much cleaner. But I think I still need an array in some form or fashion.

Thus, a couple more questions:

1) if I know I'll need an array, populated with selected file names, later in my code, can I construct such based upon which items are selected in MS ListBox1?

2) If not, and need to revert back to SEPARATE> command to build my array, am I stuck with an inherent inability to populate MS ListBox1 with the list data in the array?

Thanks again. -- Bo.
-- Bopert in Austin

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Post by strosfan47 » Wed Feb 16, 2011 3:10 pm

Perhaps an example utilizing the below MSListBox properties will get me over the hump?:
SelectedIndex
Provides the index of the item selected.

SelectedItems
Returns the selected item or if MultiSelect enabled returns a
%CRLF% delimited list of all selected items.
-- Bopert in Austin

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

Post by Marcus Tettmar » Wed Feb 16, 2011 3:14 pm

What inherent inability? I think you are misreading stuff here. There's absolutely no problem with populating a list box from an array. You just have your code all mixed up.

Here's code that correctly populates the list box from an array made by GetFileList:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 449
  Top = 266
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 0
    Top = 0
    Width = 431
    Height = 212
    Align = alClient
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 8
    SelectedIndex = -1
    ExplicitLeft = 22
    ExplicitTop = 12
    ExplicitWidth = 275
    ExplicitHeight = 97
  end
end
EndDialog>Dialog1

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF

//To populate the list all we need to do is:
//SetDialogProperty>Dialog1,MSListBox1,Text,theList

//but since you want to see how to do it from an array
//lets waste time by exploding the list to an array and THEN 
//populate the list box from that array:

//explode the list to an array:
Separate>theList,CRLF,anArray

//now walk the array and populate the list box, which is basically just turning the array back into a delimited string
Let>new_list=
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_item=anArray_%k%
  Let>new_list=%new_list%%this_item%%CRLF%
Until>k=anArray_count

//now we have reconstructed a delimited string from an array we can use it to populate the listbox
SetDialogProperty>Dialog1,MSListBox1,Text,new_list

Show>Dialog1,r

If need an array just use Separate.

So after this:

Code: Select all

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF
Do this:

Code: Select all

Separate>theList,CRLF,array
And then if you want to loop through it:

Code: Select all

Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_item=array_%k%
  ...
Until>k=array_count
To create an array from items that have been selected in the list box:

Code: Select all

//let's see which items were selected and create an array from them
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Separate>Selected_List,CRLF,array_of_selected_items
Now you have an array called array_of_selected_items and if you want to walk through it use the same loop structure as the example given above.

Putting it all together to create a multi-select list box of files in a folder populated via an array and then creating an array from the user selected items:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 802
  Top = 351
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 0
    Top = 0
    Width = 431
    Height = 212
    Align = alClient
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 0
    SelectedIndex = -1
  end
end
EndDialog>Dialog1

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF

//To populate the list all we need to do is:
//SetDialogProperty>Dialog1,MSListBox1,Text,theList

//but since you want to see how to do it from an array
//lets waste time by exploding the list to an array and THEN 
//populate the list box from that array:

//explode the list to an array:
Separate>theList,CRLF,anArray

//now walk the array and populate the list box, which is basically just turning the array back into a delimited string
Let>new_list=
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_item=anArray_%k%
  Let>new_list=%new_list%%this_item%%CRLF%
Until>k=anArray_count

//now we have reconstructed a delimited string from an array we can use it to populate the listbox
SetDialogProperty>Dialog1,MSListBox1,Text,new_list

Show>Dialog1,r

//let's see which items were selected and create an array from them
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Separate>Selected_List,CRLF,array_of_selected_items

//breakpoint here - look in the watch list and you'll see your array items
**BREAKPOINT**
Run it in the editor and then at the breakpoint look in the watch list to see the array items created.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by Marcus Tettmar » Wed Feb 16, 2011 3:18 pm

strosfan47 wrote:Perhaps an example utilizing the below MSListBox properties will get me over the hump?:
SelectedIndex
Provides the index of the item selected.

SelectedItems
Returns the selected item or if MultiSelect enabled returns a
%CRLF% delimited list of all selected items.
Run this example in the editor:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 802
  Top = 351
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 0
    Top = 0
    Width = 431
    Height = 212
    Align = alClient
    ItemHeight = 13
    MultiSelect = True
    TabOrder = 0
    SelectedIndex = -1
  end
end
EndDialog>Dialog1

GetFileList>%USERDOCUMENTS_DIR%\*.*,theList,CRLF

//To populate the list all we need to do is:
//SetDialogProperty>Dialog1,MSListBox1,Text,theList

//but since you want to see how to do it from an array
//lets waste time by exploding the list to an array and THEN 
//populate the list box from that array:

//explode the list to an array:
Separate>theList,CRLF,anArray

//now walk the array and populate the list box, which is basically just turning the array back into a delimited string
Let>new_list=
Let>k=0
Repeat>k
  Let>k=k+1
  Let>this_item=anArray_%k%
  Let>new_list=%new_list%%this_item%%CRLF%
Until>k=anArray_count

//now we have reconstructed a delimited string from an array we can use it to populate the listbox
SetDialogProperty>Dialog1,MSListBox1,Text,new_list

Show>Dialog1,r

//let's see which items were selected and create an array from them
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Separate>Selected_List,CRLF,array_of_selected_items

//breakpoint here - look in the watch list and you'll see your array items
**BREAKPOINT**
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

strosfan47
Newbie
Posts: 9
Joined: Tue Feb 15, 2011 2:57 pm

Post by strosfan47 » Wed Feb 16, 2011 3:38 pm

Thanks a million! The below examples were most helpful:
Separate>theList,CRLF,anArray
GetDialogProperty>Dialog1,MSListBox1,SelectedItems,Selected_list
Let>new_list=%new_list%%this_item%%CRLF%
I should hit my Eureka moment very soon, likely today. Thanks for your excellent support!
-- Bopert in Austin

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Fri Jul 19, 2013 6:01 pm

I take the example above and modify it to suite my needs but theres something I just dont understand how it works.

This is what I get so far.

[code]
Dialog>Dialog1
object Dialog1: TForm
Left = 449
Top = 266
HelpContext = 5000
BorderIcons = []
Caption = 'MyDialog'
ClientHeight = 212
ClientWidth = 431
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSListBox1: tMSListBox
Left = 0
Top = 0
Width = 431
Height = 212
Align = alClient
ItemHeight = 13
TabOrder = 8
SelectedIndex = -1
ExplicitLeft = 22
ExplicitTop = 12
ExplicitWidth = 275
ExplicitHeight = 97
end
end
EndDialog>Dialog1

GetFileList>C:\Datalist\*.txt,theList,CRLF
SetDialogProperty>Dialog1,MSListBox1,Text,theList

Show>Dialog1,r
[/code]

The C:\Datalist folder contains filesnames like below:
John.txt
Mary.txt
Thomas.txt
George.txt
Mon.dat
Tue.dat
Wed.dat
Thu.dat
Fri.dat
Sat.dat
Sun.dat


I just wanted to the *.txt files display in my listbox(with the X close button disable, and the listbox window have always on top enable(if possible)), without the pathname and .txt in the lisbox contains like below:

MyDialog
------------
John
Mary
George
Thomas

And the user are only allow to select one item(mouse single click) from my listbox, the selected item name is return as a variable and display in a messagemodal.

Any help on this?

Thanks

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Fri Jul 19, 2013 7:21 pm

I believe this may be what you re trying to do...
(re-edited to remove command abbreviations)

Code: Select all

Dialog>Dialog2
object Dialog2: TForm
  Left = 656
  Top = 282
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 29
    Top = 13
    Width = 132
    Height = 180
    ItemHeight = 13
    TabOrder = 8
    SelectedIndex = -1
  end
end
EndDialog>Dialog2

AddDialogHandler>Dialog2,MSListBox1,OnClick,ShowMe

GetFileList>C:\Datalist\*.txt,theList,CRLF
StringReplace>theList,C:\Datalist\,,strNewString
StringReplace>strNewString,.txt,,strNewString

SetDialogProperty>Dialog2,MSListBox1,Text,strNewString

Show>Dialog2,r

SRT>ShowMe
  GetDialogProperty>Dialog2,MSListBox1,SelectedItems,SelectedText
  MessageModal>SelectedText
END>ShowMe
Thanks,
Jerry

[email protected]

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sat Jul 20, 2013 8:18 pm

Thank you, it work perfectly.

I only cant figure out how to made the dialog show in the centre of my screen(the top = center and left = center, where should I put these centre commands, it work on normal dialog but not this listbox dialog) and also the alwaysontop window option(the FormStyle = fsStayOnTop doesnt seem to work).

Any ideas why?

Thank you.

This is my script below.

[code]
Dialog>Dialog2
object Dialog2: TForm
Left = 251
Top = 104
HelpContext = 5000
BorderIcons = []
BorderStyle = bsSingle
Caption = ' Data Listing'
ClientHeight = 212
ClientWidth = 192
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSListBox1: tMSListBox
Left = 29
Top = 13
Width = 132
Height = 180
ItemHeight = 13
TabOrder = 0
SelectedIndex = -1
end
end
EndDialog>Dialog2

AddDialogHandler>Dialog2,MSListBox1,OnClick,ShowMe

GetFileList>C:\Datalist\*.txt,theList,CRLF
StringReplace>theList,C:\Datalist\, ,strNewString
StringReplace>strNewString,.txt,,strNewString

SetDialogProperty>Dialog2,MSListBox1,Text,strNewString

Label>Start
Show>Dialog2,r

SRT>ShowMe
GetDialogProperty>Dialog2,MSListBox1,SelectedItems,SelectedText
CloseDialog>Dialog2
Trim>SelectedText,result
If>result=,Start
MessageModal>result
Exit>0
END>ShowMe
[/code]

I use Caption = ' Data Listing' to centre my title, is there a better way to do it?

Thanks.

PS-I just notice if I compiled this script into exe, when execute after selection an option, when the messagemodel showup, the dialog2 did not even close, but if run in macro scheduler script mode, it works. Did I write anything wrong with my script above?

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Jul 21, 2013 12:54 pm

I only cant figure out how to made the dialog show in the centre of my screen(the top = center and left = center, where should I put these centre commands, it work on normal dialog but not this listbox dialog)
I' don't understand, you want the list box in the center of the screen or the text aligned in the center of the list box. Can you elaborate a little more?
and also the alwaysontop window option(the FormStyle = fsStayOnTop doesnt seem to work).
In Dialog properties OnTaskbar must be set to True, Position must be set to poScreenCenter or poDesktopCenter and FormStyle to fsStayOnTop to have the dialog always stay on top.
I use Caption = ' Data Listing' to centre my title, is there a better way to do it?
There is no setting to center the caption.
PS-I just notice if I compiled this script into exe, when execute after selection an option, when the messagemodel showup, the dialog2 did not even close, but if run in macro scheduler script mode, it works. Did I write anything wrong with my script above?
Instead of CloseDialog>Dialog2 use SetDialogProperty>Dialog2,,Visible,False.

Code: Select all

Dialog>Dialog2
object Dialog2: TForm
  Left = 566
  Top = 104
  HelpContext = 5000
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = '             Data Listing'
  ClientHeight = 212
  ClientWidth = 192
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object MSListBox1: tMSListBox
    Left = 29
    Top = 13
    Width = 132
    Height = 180
    ItemHeight = 13
    TabOrder = 0
    SelectedIndex = -1
  end
end
EndDialog>Dialog2

AddDialogHandler>Dialog2,MSListBox1,OnClick,ShowMe
GetFileList>C:\Datalist\*.txt,theList,CRLF
StringReplace>theList,C:\Datalist\,         ,strNewString
StringReplace>strNewString,.txt,,strNewString
SetDialogProperty>Dialog2,MSListBox1,Text,strNewString

Label>Start
Show>Dialog2,r

SRT>ShowMe
  GetDialogProperty>Dialog2,MSListBox1,SelectedItems,SelectedText
  SetDialogProperty>Dialog2,,Visible,False
  Trim>SelectedText,result
  If>result=
    SetDialogProperty>Dialog2,,Visible,True
    Goto>Start
  ENDIF
  MessageModal>result
  Exit>0
END>ShowMe

newuser
Pro Scripter
Posts: 64
Joined: Tue Jun 11, 2013 4:53 pm

Post by newuser » Sun Jul 21, 2013 3:28 pm

Thanks Rain for your script.

[quote="Rain"]
I' don't understand, you want the list box in the center of the screen or the text aligned in the center of the list box. Can you elaborate a little more?
[/quote]
I mean both if possible.

I notice that I cant simply exit subroutine using goto command, so I modify the script again. I use END>Showme before using Goto>Start command, not sure whether this is the correct method to exit subroutine.

[code]
Dialog>Dialog2
object Dialog2: TForm
Left = 566
Top = 104
HelpContext = 5000
BorderIcons = []
BorderStyle = bsSingle
Caption = ' Data Listing'
ClientHeight = 212
ClientWidth = 192
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = True
PixelsPerInch = 96
TextHeight = 13
object MSListBox1: tMSListBox
Left = 29
Top = 13
Width = 132
Height = 180
ItemHeight = 13
TabOrder = 0
SelectedIndex = -1
end
end
EndDialog>Dialog2

AddDialogHandler>Dialog2,MSListBox1,OnClick,ShowMe
GetFileList>C:\Datalist\*.txt,theList,CRLF
StringReplace>theList,C:\Datalist\, ,strNewString
StringReplace>strNewString,.txt,,strNewString
SetDialogProperty>Dialog2,MSListBox1,Text,strNewString

Label>Start
Show>Dialog2,r

SRT>ShowMe
GetDialogProperty>Dialog2,MSListBox1,SelectedItems,SelectedText
SetDialogProperty>Dialog2,,Visible,False
Trim>SelectedText,result
If>result=
SetDialogProperty>Dialog2,,Visible,True
END>ShowMe
Goto>Start
ENDIF
MessageModal>result
Exit>0
END>ShowMe
[/code]

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Mon Jul 22, 2013 3:00 pm

"[newuser] I notice that I cant simply exit subroutine using goto command, so I modify the script again. I use END>Showme before using Goto>Start command, not sure whether this is the correct method to exit subroutine."

Probably a better way to do this is to only hide the dialog for a valid response (a name was selected) rather than always hide and then restore it.

Code: Select all

SRT>ShowMe
  GetDialogProperty>Dialog2,MSListBox1,SelectedItems,SelectedText
  Trim>SelectedText,result

  Length>result,ResultLength
  If>ResultLength>0
    SetDialogProperty>Dialog2,,Visible,False
    MessageModal>result
    Exit>0
  Endif
END>ShowMe
This way the logic of the subroutine doesn't loop back from the middle of the routine. It either exits the script completely or finishes the routine and naturally loops back to dialog.

I don't believe there is a way to center the text in the list box.
Thanks,
Jerry

[email protected]

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