Site Search:
 
TEFL International Supports Dave's ESL Cafe
TEFL Courses, TESOL Course, English Teaching Jobs - TEFL International
Korean Job Discussion Forums Forum Index Korean Job Discussion Forums
"The Internet's Meeting Place for ESL/EFL Teachers from Around the World!"
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Word macro to randomize a list of test answers
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Korean Job Discussion Forums Forum Index -> Technology Forum
View previous topic :: View next topic  
Author Message
mindmetoo



Joined: 02 Feb 2004

PostPosted: Sun Aug 28, 2005 4:35 pm    Post subject: Word macro to randomize a list of test answers Reply with quote

removed by OP

Last edited by mindmetoo on Wed Feb 25, 2009 2:37 pm; edited 5 times in total
Back to top
View user's profile Send private message
howie2424



Joined: 09 Jan 2003

PostPosted: Sun Aug 28, 2005 8:25 pm    Post subject: Reply with quote

cool, thanks very much.
Back to top
View user's profile Send private message
mindmetoo



Joined: 02 Feb 2004

PostPosted: Sun Aug 28, 2005 9:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Mon Aug 29, 2005 2:50 am    Post subject: Reply with quote

Awesome! I have been loking for that for years! Thanks so much!
Back to top
View user's profile Send private message
IlIlNine



Joined: 15 Jun 2005
Location: Gunpo, Gyonggi, SoKo

PostPosted: Mon Aug 29, 2005 8:40 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Mon Aug 29, 2005 4:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
mindmetoo



Joined: 02 Feb 2004

PostPosted: Mon Aug 29, 2005 5:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Wed Jan 04, 2006 9:38 pm    Post subject: Reply with quote

This doesn't seem to work with Word 2004 for Mac. Any ideas?
Back to top
View user's profile Send private message
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Tue Jan 24, 2006 12:00 pm    Post subject: Reply with quote

It works for me in Word 2000 under Windows XP.
Back to top
View user's profile Send private message
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Tue Jan 24, 2006 5:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
mindmetoo



Joined: 02 Feb 2004

PostPosted: Mon Mar 20, 2006 3:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
OiGirl



Joined: 23 Jan 2003
Location: Hoke-y-gun

PostPosted: Fri Jun 30, 2006 8:18 pm    Post subject: Reply with quote

Well, the strangest thing is that it was working with my previous version of Word and heritage OS.
Back to top
View user's profile Send private message
mindmetoo



Joined: 02 Feb 2004

PostPosted: Fri Jul 07, 2006 6:23 am    Post subject: Reply with quote

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
View user's profile Send private message
superbloke



Joined: 24 Jan 2008

PostPosted: Wed Nov 05, 2008 11:17 pm    Post subject: Reply with quote

Thanks very much Very Happy










------------------------------------------------------------------------

www.saveusafund.com
Back to top
View user's profile Send private message
superbloke



Joined: 24 Jan 2008

PostPosted: Wed Nov 05, 2008 11:18 pm    Post subject: Reply with quote

Thanks very much Very Happy










------------------------------------------------------------------------

www.saveusafund.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Korean Job Discussion Forums Forum Index -> Technology Forum All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


This page is maintained by the one and only Dave Sperling.
Contact Dave's ESL Cafe
Copyright © 2013 Dave Sperling. All Rights Reserved.

Powered by phpBB © 2001, 2002 phpBB Group

TEFL International Supports Dave's ESL Cafe
TEFL Courses, TESOL Course, English Teaching Jobs - TEFL International