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 =)
2 2377
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. - Public Function Jumbled(ByVal inWord As String) As String
-
' Take a word and jumble the letters
-
-
Dim Char As String * 1
-
Dim L As Long
-
Dim I As Long
-
Dim CharPos As Long
-
Randomize
-
-
L = Len(inWord)
-
If L = 0 Then Exit Function
-
outWord = Space$(L)
-
-
' Safeguard - avoid an infinite loop.
-
If InStr(inWord, " ") Then
-
Exit Function
-
End If
-
-
' Take each char in turn, copy to random spot in new "word".
-
For I = 1 To L
-
Char = Mid$(inWord, I, 1)
-
Do
-
CharPos = Rnd * L + 1 ' I'm uncertain about this line.
-
Loop While Mid$(outWord, CharPos, 1) <> " "
-
Mid$(outWord, CharPos, 1) = Char
-
Next
-
Jumbled = outWord
-
End Function
-
P.S. As far as I'm concerned, "just for fun" is the best reason for programming.
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. - Public Function Jumbled(ByVal inWord As String) As String
-
' Take a word and jumble the letters
-
-
Dim Char As String * 1
-
Dim L As Long
-
Dim I As Long
-
Dim CharPos As Long
-
Randomize
-
-
L = Len(inWord)
-
If L = 0 Then Exit Function
-
outWord = Space$(L)
-
-
' Safeguard - avoid an infinite loop.
-
If InStr(inWord, " ") Then
-
Exit Function
-
End If
-
-
' Take each char in turn, copy to random spot in new "word".
-
For I = 1 To L
-
Char = Mid$(inWord, I, 1)
-
Do
-
CharPos = Rnd * L + 1 ' I'm uncertain about this line.
-
Loop While Mid$(outWord, CharPos, 1) <> " "
-
Mid$(outWord, CharPos, 1) = Char
-
Next
-
Jumbled = outWord
-
End Function
-
It works great! Thanks alot, this really helps alot to help understanding vb :P
Great job, thanks alot :D
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
|
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...
|
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;
|
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,...
|
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ˆ...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |