View previous topic :: View next topic |
Author |
Message |
mindmetoo
Joined: 02 Feb 2004
|
Posted: Sun Aug 28, 2005 4:35 pm Post subject: Word macro to randomize a list of test answers |
|
|
removed by OP
Last edited by mindmetoo on Wed Feb 25, 2009 2:37 pm; edited 5 times in total |
|
Back to top |
|
|
howie2424
Joined: 09 Jan 2003
|
Posted: Sun Aug 28, 2005 8:25 pm Post subject: |
|
|
cool, thanks very much. |
|
Back to top |
|
|
mindmetoo
Joined: 02 Feb 2004
|
Posted: Sun Aug 28, 2005 9:27 pm Post subject: |
|
|
Sub randomizelist()
The name of the macro
Dim paragaphz(100)
Sets the array dimension at 100. If you want to sort more than 100 lines you need to bump this up.
paracount = Selection.Paragraphs.Count
This counts the number of paragraphs that have been selected and stores it in the paracount variable.
For x = 1 To paracount
paragaphz(x) = Selection.Paragraphs(x)
Next x
Loads the paragaphz array with the highlighted items. Each item in the array is a paragraph. It would appear the Selection function stores the contents of each paragraph in an array.
For y = 1 To (paracount * Int((paracount * Rnd) + 1))
The For loop will run for a random number of times. It will run at least as many times as there are highlighted paragraphs and likely more. If there are 10 items, the loop will run 10 * a random number between 1 and 10. So for example 10*5= 50 times. This should be a tip off that my randomization process is going to be highly inelegant.
Do
pararand1 = Int((paracount * Rnd) + 1)
pararand2 = Int((paracount * Rnd) + 1)
Loop While pararand1 = pararand2
Now we pick two different random numbers. One gets loaded in the pararand1 variable and one gets loaded in the pararand2 variable. If the numbers are the same (eg pararand1 = 4 and pararand2 = 4) then the Loop While function does the loop again, making the macro pick two more and keeps looping until the random function coughs up two unique numbers. Again tip off #2 that my coding is ham fisted and relies on brute force.
parastore = paragaphz(pararand1)
The parastore variable stores the contents of the first randomly selected array member.
paragaphz(pararand1) = paragaphz(pararand2)
The first randomly selected array member gets the value held in the second randomly selected array member.
paragaphz(pararand2) = parastore
The second randomly selected array member gets the value previously held in the first randomly selected array member (which was preserved in the parastore temp variable)
What we've accomplished here is just picking two random array members and having them swap values.
Next y
And this is the part where a good programmer would truly beat me about the face and neck. We do it all over again. In essence we're shuffling the deck. Randomly picking 2 list members have having them swap places. If we do this enough bloody times, the resultant list will look random enough. I know there are more elegant ways of randomizing an array that requires a lot less iteration...
For z = 1 To paracount
Selection.TypeText Text:=paragaphz(z)
Next z
Here now we spew out the shuffled array.
End Sub
An end. |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Mon Aug 29, 2005 2:50 am Post subject: |
|
|
Awesome! I have been loking for that for years! Thanks so much! |
|
Back to top |
|
|
IlIlNine
Joined: 15 Jun 2005 Location: Gunpo, Gyonggi, SoKo
|
Posted: Mon Aug 29, 2005 8:40 am Post subject: |
|
|
Not extremely efficient -- but you know what? Who cares! These days 2gHz processors are the norm. It's not like you're doing this a million times.
Thanks for your effort and I'm sure it will find a lot of use. |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Mon Aug 29, 2005 4:08 pm Post subject: |
|
|
I just now had a chance to try this and it worked! Thank you so much for reading my mind and making something I had dreamed about for years come true! |
|
Back to top |
|
|
mindmetoo
Joined: 02 Feb 2004
|
Posted: Mon Aug 29, 2005 5:37 pm Post subject: |
|
|
IlIlNine wrote: |
Not extremely efficient -- but you know what? Who cares! These days 2gHz processors are the norm. It's not like you're doing this a million times.
Thanks for your effort and I'm sure it will find a lot of use. |
Long time ago I wrote this sci fi role playing aid in visualbasic. It generated star systems. It was pretty nifty and very useful and I'd get a lot of email from people saying how great it worked, but I also included the source code. I did admit in the code that I wasn't a programmer and my coding was bletcherous to the max ("This is what happens when you create a development environment that non programmers can program in!"). I would get programmers that would agree with that statement... |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Wed Jan 04, 2006 9:38 pm Post subject: |
|
|
This doesn't seem to work with Word 2004 for Mac. Any ideas? |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Tue Jan 24, 2006 12:00 pm Post subject: |
|
|
It works for me in Word 2000 under Windows XP. |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Tue Jan 24, 2006 5:09 pm Post subject: |
|
|
OiGirl wrote: |
This doesn't seem to work with Word 2004 for Mac. Any ideas? |
It says there is a "Compile Syntax Error" in this line:
paragaphz(x) = Selection.Paragraphs(x)
Any ideas? It's Word 2004 version 11.2 running under Mac OS 10.4.4. I do wish I could work on this at home... |
|
Back to top |
|
|
mindmetoo
Joined: 02 Feb 2004
|
Posted: Mon Mar 20, 2006 3:55 pm Post subject: |
|
|
OiGirl wrote: |
OiGirl wrote: |
This doesn't seem to work with Word 2004 for Mac. Any ideas? |
It says there is a "Compile Syntax Error" in this line:
paragaphz(x) = Selection.Paragraphs(x)
Any ideas? It's Word 2004 version 11.2 running under Mac OS 10.4.4. I do wish I could work on this at home... |
Mac word probably uses a different macro language so the macro probably won't run on Mac. |
|
Back to top |
|
|
OiGirl
Joined: 23 Jan 2003 Location: Hoke-y-gun
|
Posted: Fri Jun 30, 2006 8:18 pm Post subject: |
|
|
Well, the strangest thing is that it was working with my previous version of Word and heritage OS. |
|
Back to top |
|
|
mindmetoo
Joined: 02 Feb 2004
|
Posted: Fri Jul 07, 2006 6:23 am Post subject: |
|
|
OiGirl wrote: |
Well, the strangest thing is that it was working with my previous version of Word and heritage OS. |
Word's macro language can radically change in versions. |
|
Back to top |
|
|
superbloke
Joined: 24 Jan 2008
|
Posted: Wed Nov 05, 2008 11:17 pm Post subject: |
|
|
Thanks very much
------------------------------------------------------------------------
www.saveusafund.com |
|
Back to top |
|
|
superbloke
Joined: 24 Jan 2008
|
Posted: Wed Nov 05, 2008 11:18 pm Post subject: |
|
|
Thanks very much
------------------------------------------------------------------------
www.saveusafund.com |
|
Back to top |
|
|
|