Hey everyone!
I'm trying to make a script where a user can add "names" to a list and it will randomly pick a result... Sort of like a lotto.
I'm trying to work out a way for my script to work out how many names have been added. Can you think of a way to count the number of lines in a variable.
For example, if my variable was:
Name 1
Name 2
Name 3
Could my script work out there were 3 names here so I could then make it pick a number between 1-3. (Once I know how to count the lines, I should be right with the rest!
Thanks in advance for your help!
Dominic Fichera
Count Lines in a String
Moderators: Dorian (MJT support), JRL
-
- Pro Scripter
- Posts: 82
- Joined: Mon Mar 24, 2014 12:15 pm
-
- Pro Scripter
- Posts: 82
- Joined: Mon Mar 24, 2014 12:15 pm
Re: Count Lines in a String
*UPDATE*
I've been able to answer my own question by digging through some old forum posts and using the separate function!
As an additional question, is there anyway to now decide "okay, my random number is 2, what is sitting on line 2 of the combo box"?
Thanks again!
Dominic Fichera
I've been able to answer my own question by digging through some old forum posts and using the separate function!
As an additional question, is there anyway to now decide "okay, my random number is 2, what is sitting on line 2 of the combo box"?
Thanks again!
Dominic Fichera
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Count Lines in a String
Same way really. Get list of items, use Separate to get into an array, look up item at random position:
Code: Select all
//get a random number between 1 and 3
Random>2,randnumber
Add>randnumber,1
//get the list of items from combobox
GetDialogProperty>Dialog1,MSComboBox1,ListText,itemList
Separate>itemlist,CRlF,item_array
//get item at random number position
Let>random_item=item_array_%randnumber%
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 82
- Joined: Mon Mar 24, 2014 12:15 pm
Re: Count Lines in a String
Thanks Marcus! It's up and running now!
Appreciate your help
Kind regards,
Dominic Fichera
Appreciate your help
Kind regards,
Dominic Fichera