Text from an array to populate a list box?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

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

Post by Rain » Mon Jul 22, 2013 3:01 pm

You don't need to add Goto>Start after END>ShowMe. END>ShowMe ends the subroutine and returns to Show>Dialog2,r
You can read more about how subroutines work here http://www.mjtnet.com/manual/srt.htm?zo ... ghtsub=srt


There is no property setting to center the text of a list box.

I'm not sure what look you are going for. I've modified your dialog to open in the center of the screen with the list box in the center of the dialog and removed Goto>Start since it's not needed.

Code: Select all

Dialog>Dialog2
object Dialog2: TForm
  Left = 362
  Top = 132
  HelpContext = 5000
  AutoSize = True
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = ' Data Listing'
  ClientHeight = 180
  ClientWidth = 132
  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 = 0
    Top = 0
    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
  ENDIF
  MessageModal>result
  Exit>0
END>ShowMe


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

Post by newuser » Mon Jul 22, 2013 4:56 pm

Thank you Rain and Jerry. The reason I wanted the centre of the text in the listbox is because it would look like this below:


Data Listing
---------------
---Thomas
-----Mary
-----John
---George

Instead of below:

Data Listing
---------------
--Thomas
--Mary
--John
--George

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 5:14 pm

I have seen an example (not in the Micro Scheduler forums) where someone counted the number of characters in a text string and then padded with spaces before that string to get everything centered. You would have to use a non proportional font for that to work.

The code would not be very difficult to write...
(PSEUDO Code)
Let>MaxLength = # of characters the listbox will hold in 1 row
Let>StrLength = length of the string for a row
Add padding equal to 1/2(MaxLength - StrLength)
Thanks,
Jerry

[email protected]

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

Post by newuser » Mon Jul 22, 2013 6:58 pm

That might just work, Jerry but I'll need more time on that(I mean later). My script is almost complete below:

[code]
Dialog>Dialog2
object Dialog2: TForm
Left = 566
Top = 104
HelpContext = 5000
BorderIcons = []
BorderStyle = bsSingle
Caption = ' Data Listing'
ClientHeight = 212
ClientWidth = 192
Color = 12615808
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
Color = clBlack
ItemHeight = 13
TabOrder = 0
SelectedIndex = -1
end
end
EndDialog>Dialog2


SetDialogObjectFont>Dialog2,,Arial,10,1,255



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

Length>theList,Len

If>Len=0
MessageModal>File not available
Exit>0
Endif

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
Trim>SelectedText,result

Length>result,ResultLength
If>ResultLength>0
SetDialogProperty>Dialog2,,Visible,False
MessageModal>result
Exit>0
Endif
END>ShowMe
[/code]

Theres just one thing I cant figure out, that is how to change the Dialog Caption fontsize/colour/style and also the Dialog title bar colour too.

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 7:25 pm

You are out of luck changing Dialog caption properties.

I don't believe there is any way to do that.
Thanks,
Jerry

[email protected]

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

Post by Rain » Tue Jul 23, 2013 12:02 am

You could create your title bar with and image. Here is a script a wrote a while back that will change the title bar with images I created. I kept the title bar images small in this example but you will get the idea.

You can get the script by clicking here

Image

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

Post by newuser » Tue Aug 20, 2013 1:55 pm

Thanks Rain but that also will have to wait.

I already use the sample I posted in my previous post.

But now one big problem here.

How to made a image listbox instead?

Something like a image/picture/icon for each item in the listbox.

Is there any thread in the forum that have something like/similar to this below:

Image

Image

Image

Image

Thanks alot.

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