ListBox dialog control - how to loop and count
Moderators: Dorian (MJT support), JRL
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
ListBox dialog control - how to loop and count
Hi, can someone help me and show me how to count the total items in a list.
How to loop, from the beginning of the list to the end of the list.
Thank you!
How to loop, from the beginning of the list to the end of the list.
Thank you!
- Grovkillen
- Automation Wizard
- Posts: 1128
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: ListBox dialog control - how to loop and count
Do you mean a list in an external application?
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
Thank you for your response. I should have specify.
It's the MS ListBox control of the dialog.
I want to iterate thru the ListBox from the first item to the last.
Thank you!
It's the MS ListBox control of the dialog.
I want to iterate thru the ListBox from the first item to the last.
Thank you!
- Dorian (MJT support)
- Automation Wizard
- Posts: 1378
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ListBox dialog control - how to loop and count
Like this :
That gets all the contents. You can then use Separate on the result, if you wish. In the case of the sample below, we could separate by CRLF
Code: Select all
GetDialogProperty>Dialog1,MSListBox1,Text,TheText
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 2322
Top = 431
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 428
ClientWidth = 1170
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -28
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 240
TextHeight = 32
object MSListBox1: tMSListBox
Left = 513
Top = 47
Width = 242
Height = 194
Style = lbOwnerDrawFixed
ItemHeight = 32
Items.Strings = (
'Red'
'Blue'
'Green'
'Yellow')
TabOrder = 0
Text = 'Red'#13#10'Blue'#13#10'Green'#13#10'Yellow'#13#10
SelectedIndex = -1
end
object MSButton1: tMSButton
Left = 792
Top = 190
Width = 150
Height = 50
Caption = 'Go!'
TabOrder = 9
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,DoClick
show>Dialog1,res
SRT>DoClick
GetDialogProperty>Dialog1,MSListBox1,Text,TheText
MDL>TheText
Separate>TheText,CRLF,Elements
let>theloop=0
repeat>theloop
let>theloop=theloop+1
mdl>Elements_%theloop%
Until>theloop,Elements_count
End>DoClick
Yes, we have a Custom Scripting Service. Message me or go here
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
That is great Dorian. Than you!
If I want to output de content of the listbox to an existing or new excel
what should I do.
Thank you again!
If I want to output de content of the listbox to an existing or new excel
what should I do.
Thank you again!
- Dorian (MJT support)
- Automation Wizard
- Posts: 1378
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ListBox dialog control - how to loop and count
Just write it to Excel instead. Something like this should get you started.
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 2322
Top = 431
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 428
ClientWidth = 1170
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -28
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 240
TextHeight = 32
object MSListBox1: tMSListBox
Left = 513
Top = 47
Width = 242
Height = 194
Style = lbOwnerDrawFixed
ItemHeight = 32
Items.Strings = (
'Red'
'Blue'
'Green'
'Yellow')
TabOrder = 0
Text = 'Red'#13#10'Blue'#13#10'Green'#13#10'Yellow'#13#10
SelectedIndex = -1
end
object MSButton1: tMSButton
Left = 792
Top = 190
Width = 150
Height = 50
Caption = 'Go!'
TabOrder = 9
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,DoClick
show>Dialog1,res
SRT>DoClick
GetDialogProperty>Dialog1,MSListBox1,Text,TheText
XLCreate>d:\new.xlsx,1,xlbook
XLAddSheet>xlbook,MySheet
// MDL>TheText
Separate>TheText,CRLF,Elements
let>theloop=0
repeat>theloop
let>theloop=theloop+1
// mdl>Elements_%theloop%
XLSetCell>xlbook,MySheet,%theloop%,1,Elements_%theloop%,res
Until>theloop,Elements_count
End>DoClick
Yes, we have a Custom Scripting Service. Message me or go here
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
Thank you Dorian! This is amazing. I have enough
code snipets to play for the rest of the day.
code snipets to play for the rest of the day.
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
Hi! I'm stock with my little project, can you help me.
I would like to use the variables in the dialog to automate Google and a website.
If it is hardcoded in sthe script it works. But when I start a the Google session
variables are not recognised.
This is a pricture of the dialog and the website.
Thank you again for your prcious help.
https://u.pcloud.link/publink/show?code ... OQDQrgXdeX
I would like to use the variables in the dialog to automate Google and a website.
If it is hardcoded in sthe script it works. But when I start a the Google session
variables are not recognised.
This is a pricture of the dialog and the website.
Thank you again for your prcious help.
https://u.pcloud.link/publink/show?code ... OQDQrgXdeX
- Dorian (MJT support)
- Automation Wizard
- Posts: 1378
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ListBox dialog control - how to loop and count
If you see %VariableName% in place of the actual variable, it means that variable doesn't exist.
For example:
So go back to that part of your code and investigate.
Here are two resources that will help you :
https://help.mjtnet.com/article/7-using-the-debugger
https://help.mjtnet.com/article/42-usin ... t-creation
For example:
Code: Select all
let>VariableName=Hello
MessageModal>%VriableNam%
MessageModal>VriableNam
MessageModal>VariableName
MessageModal>%VariableName%
Here are two resources that will help you :
https://help.mjtnet.com/article/7-using-the-debugger
https://help.mjtnet.com/article/42-usin ... t-creation
Yes, we have a Custom Scripting Service. Message me or go here
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
Thank you Dorian for your answer. Always helpful.
The value is not showed because the option of the combobox "Choisir le taux" is not fill".
The question remain anyway.
Now that the Dialog is build. I want to be able to use the assigned variable, and most important
the listbox items.
When I launch Google, and the website and I want to automate it's navigation, the Dialog variables
are not recognize. I'ts instance seems to be "detached" from the script.
Is there a way to make those Dialog variables be part again like a Dialog1.%varName%?
Thank you!
The value is not showed because the option of the combobox "Choisir le taux" is not fill".
The question remain anyway.
Now that the Dialog is build. I want to be able to use the assigned variable, and most important
the listbox items.
When I launch Google, and the website and I want to automate it's navigation, the Dialog variables
are not recognize. I'ts instance seems to be "detached" from the script.
Is there a way to make those Dialog variables be part again like a Dialog1.%varName%?
Thank you!
- Dorian (MJT support)
- Automation Wizard
- Posts: 1378
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ListBox dialog control - how to loop and count
Let's take a step back and forget Google and the website for now,. Let's make sure the variables are what you think they are. (You could do this with the debugger I showed you in the previous reply).
If you simply use MessageModal>%MyVariable% (of course edit this), do you see what you expect? If no, then examine carefully with the debugger. If yes, then we need to take the next steps to enter those details into the browser.
If we're using IE we can use the Find IE element Wizard. Or for Chrome you can use the Chrome Functions. If it can simply be encoded into a URL you could ExecuteFile the URL.
Either way, any variables created in Macro Scheduler should be passed to another application as simply as creating a variable and typing it into Notepad.
If you simply use MessageModal>%MyVariable% (of course edit this), do you see what you expect? If no, then examine carefully with the debugger. If yes, then we need to take the next steps to enter those details into the browser.
If we're using IE we can use the Find IE element Wizard. Or for Chrome you can use the Chrome Functions. If it can simply be encoded into a URL you could ExecuteFile the URL.
Either way, any variables created in Macro Scheduler should be passed to another application as simply as creating a variable and typing it into Notepad.
Code: Select all
Let>MyVar=Hello
run>Notepad
WaitWindowOpen>Untitled*
SetFocus>Untitled*
Send>%MyVar%
Yes, we have a Custom Scripting Service. Message me or go here
-
- Pro Scripter
- Posts: 90
- Joined: Fri Jan 31, 2020 10:52 am
Re: ListBox dialog control - how to loop and count
Again Thank you Dorian! I had to changed the window title. In french it is "Sans titre - Bloc-notes"
Work perfect. Nothing like going back to basic.
I'll go and apply to my project.
Work perfect. Nothing like going back to basic.
I'll go and apply to my project.
- Dorian (MJT support)
- Automation Wizard
- Posts: 1378
- Joined: Sun Nov 03, 2002 3:19 am
- Contact:
Re: ListBox dialog control - how to loop and count
Always happy to help (even if I don't always understand the question the first time).
Yes, we have a Custom Scripting Service. Message me or go here