473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Randomizing order of letters?

I am currently doing a kind of a game, mostly for fun :P

Anyways, its a word game, and i want a label to show a word with the letters of a word i have in a variable/array totally scattered, so that they have mixed places from what they had before..
Example: the label says uprsies (or something like that) and the user should enter suprise in a textbox...

But, what i need help wit his how to make the words scatter?? (using vb6 btw)

Some help would be greatly appriciated =)
Dec 6 '06 #1
2 2377
Killer42
8,435 Expert 8TB
I am currently doing a kind of a game, mostly for fun :P

Anyways, its a word game, and i want a label to show a word with the letters of a word i have in a variable/array totally scattered, so that they have mixed places from what they had before..
Example: the label says uprsies (or something like that) and the user should enter suprise in a textbox...

But, what i need help wit his how to make the words scatter?? (using vb6 btw)

Some help would be greatly appriciated =)
For starters, you might want to get a dictionary if you're writing a word game. Don't want any nasty "suprises" ;)

Secondly, here's some code which might help. I've just coded it in VB, but haven't tested it - good luck! If the passed "word" contains any spaces, it will drop out. Otherwise, I believe my logic would have caused an infinite loop.
Expand|Select|Wrap|Line Numbers
  1. Public Function Jumbled(ByVal inWord As String) As String
  2.   ' Take a word and jumble the letters
  3.  
  4.   Dim Char As String * 1
  5.   Dim L As Long
  6.   Dim I As Long
  7.   Dim CharPos As Long
  8.   Randomize
  9.  
  10.   L = Len(inWord)
  11.   If L = 0 Then Exit Function
  12.   outWord = Space$(L)
  13.  
  14.   ' Safeguard - avoid an infinite loop.
  15.   If InStr(inWord, " ") Then
  16.     Exit Function
  17.   End If
  18.  
  19.   ' Take each char in turn, copy to random spot in new "word".
  20.   For I = 1 To L
  21.     Char = Mid$(inWord, I, 1)
  22.     Do
  23.       CharPos = Rnd * L + 1 ' I'm uncertain about this line.
  24.     Loop While Mid$(outWord, CharPos, 1) <> " "
  25.     Mid$(outWord, CharPos, 1) = Char
  26.   Next
  27.   Jumbled = outWord
  28. End Function
  29.  
P.S. As far as I'm concerned, "just for fun" is the best reason for programming.
Dec 6 '06 #2
For starters, you might want to get a dictionary if you're writing a word game. Don't want any nasty "suprises" ;)
.
Thanks for the tip, think ill get the program working first though :D

P.S. As far as I'm concerned, "just for fun" is the best reason for programming.
I couldn't agree more :D


Secondly, here's some code which might help. I've just coded it in VB, but haven't tested it - good luck! If the passed "word" contains any spaces, it will drop out. Otherwise, I believe my logic would have caused an infinite loop.
Expand|Select|Wrap|Line Numbers
  1. Public Function Jumbled(ByVal inWord As String) As String
  2.   ' Take a word and jumble the letters
  3.  
  4.   Dim Char As String * 1
  5.   Dim L As Long
  6.   Dim I As Long
  7.   Dim CharPos As Long
  8.   Randomize
  9.  
  10.   L = Len(inWord)
  11.   If L = 0 Then Exit Function
  12.   outWord = Space$(L)
  13.  
  14.   ' Safeguard - avoid an infinite loop.
  15.   If InStr(inWord, " ") Then
  16.     Exit Function
  17.   End If
  18.  
  19.   ' Take each char in turn, copy to random spot in new "word".
  20.   For I = 1 To L
  21.     Char = Mid$(inWord, I, 1)
  22.     Do
  23.       CharPos = Rnd * L + 1 ' I'm uncertain about this line.
  24.     Loop While Mid$(outWord, CharPos, 1) <> " "
  25.     Mid$(outWord, CharPos, 1) = Char
  26.   Next
  27.   Jumbled = outWord
  28. End Function
  29.  
It works great! Thanks alot, this really helps alot to help understanding vb :P
Great job, thanks alot :D
Dec 6 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: D. Roshani | last post by:
Hello ! I wonder if any one can help me to create a cosomize sorting order (as Macro or added small program in c++ or c# which does this work) in a Access Database contaning one table only words...
2
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The...
4
by: Deborah V. Gardner | last post by:
I have a field with values like this CO 03-10 CO 03-4 VI 03-8 CO 03-533 I would like these to sort for a report by the first two letters and the digits after the hyphen (-) like this
3
by: D r . P r o z a c | last post by:
Hi, I want to identify combinations of letters (a-z)... to make the combination unique, but where the order of these letters is not important. For example: 'er' and 're' should have the same...
8
by: vijay | last post by:
Hello, As the subject suggests, I need to print the string in the reverse order. I made the following program: # include<stdio.h> struct llnode { char *info;
6
by: Paul van Brenk | last post by:
When you run the Shuffle method often enough it will throw exception. And I can't figure out why. Anybody? Paul van Brenk the code: static void Shuffle(){ int ints = { 1, 2, 3, 4, 5, 6,...
2
by: adrian.chandler | last post by:
Hi all, I have been using letter and symbol codes such as GNU< GNU\ GNU} GNUˆ in an Access table. I was surprised to see that when the table was sorted on this field, the order is: GNUˆ...
2
by: utahwrx | last post by:
I currently have a Javascript application that randomizes about 200 images. The problem is that the images preload, which causes the entire site to not come up until all the images are loaded. I'd...
16
mshmyob
by: mshmyob | last post by:
I am trying to randomize my filter. I have a table with a record that has a possible value of "Easy", "Medium", or "Hard". The user makes a choice by a combo box. After it is chosen I activate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.