 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Needs help Guest
|
Posted: Fri Oct 23, 2009 12:45 am Post subject: How to randomize a bunch of links according to checkboxes. |
|
|
I have a GUI that I've created, it has a serious of categories with check boxes.
What I wanted it to do, the user picks which categories they want to be added to the randomization, then they click start, and it will randomly select a link, from all the included categories.
Does that make sense? If not, ask for more detail. |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Fri Oct 23, 2009 1:04 am Post subject: |
|
|
I commend you for your subject title, Very Good!
I suggest that your code collect a list of the suitable links, based on the selected catogories, count them, and then apply this command:
http://www.autohotkey.com/docs/commands/Random.htm
There may be many ways to collect the list, but further discussion probably should be based on you code.
Can you post your code with code tags please? |
|
| Back to top |
|
 |
Needs help Guest
|
Posted: Fri Oct 23, 2009 1:53 am Post subject: |
|
|
| Leef_me wrote: | I commend you for your subject title, Very Good!  | I don't understand what you mean by that.
| Code: | Gui, Font, S34 CGreen, Papyrus
Gui, Add, Text, x3 y0 w310 h130 +Center, Random Link Generator
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Text, x3 y140 w310 h80 +Center, Choose the lists of links you would like to add.
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Checkbox, x56 y210 w190 h30 Checked, Blogs
Gui, Add, Checkbox, x56 y250 w180 h30 Checked, Game sites
Gui, Add, Checkbox, x56 y290 w140 h30 Checked, MMORPG's
Gui, Add, Checkbox, x56 y330 w160 h30 Checked, Pictures
Gui, Add, Button, x108 y370 w100 h30 , Choose!
Gui, Show, w319 h410, Test Gui
Return
GuiClose:
ExitApp |
Is my GUI, I have added no code yet, as I want to think of a method before I start.
Example:
I want checkbox1 to contain the links: MyYearBook.com, Myspace.com, and Facebook.com
Checkbox2 to contain the links: Addictinggames.com, Miniclip.com, and Armorgames.com
Checkbox3 to contain the links: Worldofwarcraft.com, Ashenempires.com, Rappelz.gPotato.com
Checkbox4 to contain the links: Tinypic.com, Imageshack.us, Photobucket.com
Whenever the checkbox is checked, those links are added to the pile of links to randomize. When you click the button Choose! I want it to randomly select only ONE link out of the group of links I've selected.
I tried to set it to random a number between 1 and however many links there are and set each link to an individual number, but that means I would have to right a code for every possible outcome, which is very inconventient. |
|
| Back to top |
|
 |
Needs help Guest
|
Posted: Fri Oct 23, 2009 5:42 am Post subject: |
|
|
I've added a little code to my script. I've decided to go the route and hard code every possible outcome. This is what I have.
| Code: | Gui, Font, S34 CGreen, Papyrus
Gui, Add, Text, x3 y0 w310 h130 +Center, Random Link Generator
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Text, x3 y140 w310 h80 +Center, Choose the lists of links you would like to add.
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Checkbox, x56 y210 w190 h30 Checked vblog, Blogs
Gui, Add, Checkbox, x56 y250 w180 h30 Checked vgame, Game sites
Gui, Add, Checkbox, x56 y290 w140 h30 Checked vmmo, MMORPG's
Gui, Add, Checkbox, x56 y330 w160 h30 Checked vpic, Pictures
Gui, Add, Button, x108 y370 w100 h30 , Choose
Gui, Show, w319 h410, Test Gui
Return
buttonchoose:
if(blog = 1 & game = 0 & mmo = 0 & pic = 0)
random, num, 1, 3
1 := "http://myspace.com"
2 := "http://facebook.com"
3 := "http://myyearbook.com"
msgbox, %num%
run, %num%
Return
GuiClose:
ExitApp |
The messagebox keeps returning the number. I thought that it'd set the number to a website... Then I could just tell it to run that number, but it won't work that way.  |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Fri Oct 23, 2009 5:59 am Post subject: |
|
|
| Needs help wrote: | | Leef_me wrote: | I commend you for your subject title, Very Good!  | I don't understand what you mean by that. |
Some of the thread titles here are poorly thought out. Others well thought and others are mid-way between. Sorry to digress.
Maybe you'll like this better:
| Code: | Gui, Font, S34 CGreen, Papyrus
Gui, Add, Text, x3 y0 w310 h130 +Center, Random Link Generator
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Text, x3 y140 w310 h80 +Center, Choose the lists of links you would like to add.
Gui, Font, S16 CGreen, Papyrus
Gui, Add, Checkbox, x56 y210 w190 h30 vcbox1 Checked, Blogs
Gui, Add, Checkbox, x56 y250 w180 h30 vcbox2 Checked, Game sites
Gui, Add, Checkbox, x56 y290 h30 vcbox3 Checked, MMORPG's
Gui, Add, Checkbox, x56 y330 w160 h30 vcbox4 Checked, Pictures
Gui, Add, Button, x108 y370 w100 h30 vchs, Choose
Gui, Show, w319 h410, Test Gui
return
buttonchoose:
;msgbox
gui, submit, nohide
full= ; clear the list to gather
if cbox1
full:= "MyYearBook.com,Myspace.com,Facebook.com,"
if cbox2
full:=full . "Addictinggames.com,Miniclip.com,Armorgames.com,"
if cbox3
full:=full . "Worldofwarcraft.com,Ashenempires.com,Rappelz.gPotato.com,"
if cbox4
full:=full . "Tinypic.com,Imageshack.us,Photobucket.com,"
full:=full . "empty" ; always one extra entry because of the trailing comma
;msgbox %full% ; the full list
Loop, parse, full, `,
{
; MsgBox, website number %A_Index% is %A_LoopField%
b_index:=a_index-1
}
msgbox %b_index%
Random, choice , 1, %b_index%
; msgbox %choice% ; the resulting choice number
Loop, parse, full, `,
{
; MsgBox, website number %A_Index% is %A_LoopField%
if (choice=a_index)
{
result:=A_LoopField ; the resulting website
break
}
}
msgbox %result%
Return
esc::
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
Needs help Guest
|
Posted: Fri Oct 23, 2009 6:42 am Post subject: |
|
|
Wow, thanks a bunch. That's exactly what I was wanting.  |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1158 Location: San Diego, California
|
Posted: Fri Oct 23, 2009 7:03 am Post subject: |
|
|
| Needs help wrote: | Wow, thanks a bunch. That's exactly what I was wanting.  | I am pleased that I could help.
Did you notice that I changed this line (because of line wrap) | Code: | | Gui, Add, Checkbox, x56 y290 h30 vcbox3 Checked, MMORPG's |
Also, all the checkboxes need variable names to retrieve their values.
BTW, I like that font Papyrus, that was of benefit to me.  |
|
| Back to top |
|
 |
Needs help Guest
|
Posted: Fri Oct 23, 2009 4:16 pm Post subject: |
|
|
To be completely honest, I changed the GUI up a bit again.
The Papyrus font is one of my favorite fonts to use on GUI's. Glad I could show you it. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|