[RESOLVED] Random Generator for words?
Ok, basically this is a two part question.
1. Is it possible to have vb.net piece together a legitimate word of a specified length, or do I need to have a massive word list, and generate a random number to pick a word from this list?
2. I also need to separate each letter of the word and display an image for each letter, and each letter going to the next based on a timer, and can also repeat on a button click.
Eg: TWO would end up displaying T W O, a few seconds apart from each other.
If you have any questions about what I'm trying to do, look at this website:
http://asl.ms/
It has the javascript equivalent of what I want to accomplish in vb.net
Thanks for any help you offer.
Re: Random Generator for words?
Quote:
1. Is it possible to have vb.net piece together a legitimate word of a specified length, or do I need to have a massive word list, and generate a random number to pick a word from this list?
What is a "legitimate" word?
Re: Random Generator for words?
Ok, legitimate as in its actually in the English language, and not something like:
takiej, which would make no sense, and more something like: Two, Or, As, Together, But, and so on.
Re: Random Generator for words?
How do you imagine VB would do this without a list of acceptable words?
Re: Random Generator for words?
Maybe something that could pull words from Microsoft Words dictionary. I have no idea if its possible though.
Re: Random Generator for words?
Ok, I assumed I'd need to supply a wordlist, but it was worth asking.
Ok, lets say I have my text file, and I load it into an array, now I need to select a random word from that array, and break the word into letters, displaying an image for each letter that lasts for a few seconds, how can I do this?
Re: Random Generator for words?
By Image do you mean literally in a PictureBox or just in a Label?
Search (the forums or google) for reading text files by line.
Re: Random Generator for words?
OK I was just pointing out that in a general purpose programming language you're not going to find natural language validation!
Given any string you can find a character at a given position using the Substring function, eg
Code:
for X as integer = 0 to myWord.Length-1
myLetter = myWord.Substring(x,1)
next X
Re: Random Generator for words?
I literally mean PictureBox, and I already did a search for Reading Txt files line by line into arrays, and got that code.
Basically, once it generates a number, it picks it from the array, and then breaks that specified word apart into single letters, showing an image file (like g.png or y.png) for each letter, lasting for a couple of seconds.
Re: Random Generator for words?
Re: Random Generator for words?
Hi,
You can perhaps use a spellchecker in your application.
Here's an example how to use it.
Re: Random Generator for words?
How about just download a dictionary of words as a text file? put them in a List object and you can select words at random.
Re: Random Generator for words?
For generating random words, you will need a word list, load it to an array and generate a random index to get a random word.
As for showing the letters as images, you will need the images of all the letters. Load it into a dictionary(of char, image) and using the letter itself as the key, the image as the value. When you have a word, just loop thru each character in the string and pull off the correct image from the dictionary to display in your picturebox.
Re: Random Generator for words?
Quote:
When you have a word, just loop thru each character in the string and pull off the correct image from the dictionary to display in your picturebox.
Any Easy loop method to do this?
Re: Random Generator for words?
You can do something like this:
Code:
'Declare a dictionary with class scope
Private letterImages As New Dictionary(Of Char, Image)
'=================================================================
'Then in form load or some other approriate event, load the dictionary with letter images
letterImages.Add("a"c, Image.FromFile("path to the image of letter a here"))
letterImages.Add("b"c, Image.FromFile("path to the image of letter b here"))
letterImages.Add("c"c, Image.FromFile("path to the image of letter c here"))
'keep on going to load the dictionary with images of the letters in the alphabet
'
letterImages.Add("Z"c, Image.FromFile("path to the image of letter Z here"))
'================================================================
'When you want to show the images of the letters in a string, loop thru a string and display the images of the letters
Dim s As String = "Hello"
For Each ch As Char In s
'Test to see if there is a coressponding image for this letter
If letterImages.ContainsKey(ch) Then
'If there is, show it
PictureBox1.Image = letterImages(ch)
PictureBox1.Refresh()
'Pause 2 seconds
System.Threading.Thread.Sleep(2000)
End If
Next
Re: Random Generator for words?
Thank you very much for this stanav! Now that I see what to do, it seems simpler than I thought it would be.
Thank you all for the help!
Re: [RESOLVED] Random Generator for words?
Hey, I was looking into stanav's code, but what does the letter "c" (the one after "a") mean in this line of code:
vb.net Code:
letterImages.Add("a"c, Image.FromFile("path to the image of letter a here"))
(I know this thread is resolved, but I didn't know if I should've opened a new thread to post my question..)
Re: [RESOLVED] Random Generator for words?
probably character, like you can use I for integer after a number.
vb.net Code:
Dim x As Integer = 25I ' The I automatically means integer....or so I have been told this.
Re: [RESOLVED] Random Generator for words?
In your example "I" would mean Integer or the Dim'ed integer?
Re: [RESOLVED] Random Generator for words?
"I" would mean just Integer. Its automatically telling the compiler that it is an integer, even though it was defined as an integer.