Blog Archive

Thursday, May 20, 2010

Developing a New Jumble Word Game in Excel.

I am learning VBA and I am fond of word games such as Text twist and Spellathon. When I was at IIT Delhi, I used to play a game by the name "Jumble fever" (using DC++ , Ptokax and lua scripts etc). I was looking forward to downloading similar game from the internet however I couldn't find any to my satisfaction. The problem with text twist and spellathon is that they are limited to words of 7 or 8 letters (and you can't customize them with your own words) . So I thought I might as well write my own code in excel for doing something similar to "Jumble fever" using excel (Why excel,... well I came across a cool GRE worlist game written in Excel by someone called simran somewhere in US, loved it,-- it was customizable with your own words, you could even use it to learn foreign vocabulary. That program is available here: http://simran.crownpac.net/blog/wp-content/plugins/download-monitor/download.php?id=1). The first step I needed was to develop a code for randomizing any given string. Of course I am yet to develop the entire game but the first part (randomizing of a string) is over. (It took me whole day to develop just this much code, I am a dummy in VBA). Feeling very happy about the code. So here it is for benefit of anyone around the world. (BTW if you have anything with the functionality similar to Jumble fever for a standalone PC please do share with me). (Spellathon is also a cool game and can be downloaded from here: http://www.freewarefiles.com/Spellathon_program_49479.html )

Here's the code:
(VBA CODE to RANDOMIZE ANY GIVEN STRING in EXCEL)
---------------------------------------------------------------------
Function randomize(s)

newstr = ""

sl = Len(s)

For i = 1 To sl

strlen = Len(s)

c = Application.RandBetween(1, strlen)

ch = Mid(s, c, 1)

newstr = newstr & ch

s = Application.Replace(s, c, 1, "")

Next i

randomize = newstr

End Function
---------------------------------------------------------------------

How to use this code:

Open the developer VBA window in excel (alt +F11)

Insert New Module

Copy and Paste the above code (between the dashed lines)

Now you can use the "randomize" function in excel just as any other function (such as len etc). For example randomize("ambarish") may output "hsirabma"


Hope you like it.

Comments are welcome.

(I wrote this code and posted it on the net because even after an extensive google search I could not come across a VBA function in excel to do such a seemingly simple task).

No comments: