Visual Basic .NET Forums  

Go Back   Visual Basic .NET Forums > VB.NET > VB.NET General Discussion

VB.NET General Discussion VB.NET general discussion area

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-11-2008, 10:09 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Oct 2008
Posts: 5
Reputation: 0
matty is on a distinguished programming path ahead
Default VB Word Jumbler, not scrambler :)

Hello all,

I'm not the best when it comes to this, but i've been banging my head for days and i think its time i try to ask some of the very talented ppl i see on this site a quick question.
I stumbled across this post from about 2 months ago...
Basic Word Jumber

What that post is about is almost exactly what i need...except i dont want the characters in the individual words to be changed, i just need the whole words moved around. For example a text file/box that contains this "Jim Tire Tall2 G'night" would be "jumbled" or rearanged randomly to "Tall2 Jim G'night Tire". So far i have this code done, but it only gives me one word at a time, not all the words all at once.

Code:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Dim MyArray() As String = Split(testtxtbox1.Text, " ")
        Dim I As Integer
        Dim Index1 As Integer
        Dim Index2 As Integer
        Dim Temp As String

        For I = 1 To 20
            Index1 = Int(Rnd() * 10)
            Index2 = Int(Rnd() * 10)
            While Index1 = Index2
                Index2 = Int(Rnd() * 10)
            End While
            Temp = MyArray(Index1)
            MyArray(Index1) = MyArray(Index2)
            MyArray(Index2) = Temp
        Next I

        testtxtbox2.Text = Temp


    End Sub
One last thing....lets say there are 1000 words in this text file that i want to "jumble" up - but out of those 1000 words i specify in the program that i want only 500 random words out of that 1000 word file. Any ideas? Thanks in advance everyone!

Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-12-2008, 7:20 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Same concept, almost same code:
Code:
Private r As New Random
Private Function RandomizeWords(ByVal text As String) As String
    Dim words As New List(Of String)(text.Split(" "c))
    Dim newwords As New List(Of String)
    For Each word As String In words
        newwords.Insert(r.Next(0, newwords.Count + 1), word)
    Next
    Return String.Join(" ", newwords.ToArray)
End Function
Quote:
One last thing....lets say there are 1000 words in this text file that i want to "jumble" up - but out of those 1000 words i specify in the program that i want only 500 random words out of that 1000 word file. Any ideas? Thanks in advance everyone!
For example take 500 random picks from that "words" variable in example, remove the picked item as you go.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-12-2008, 3:31 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Oct 2008
Posts: 5
Reputation: 0
matty is on a distinguished programming path ahead
Default

Quote:
Originally Posted by JohnH View Post
Same concept, almost same code:
Code:
Private r As New Random
Private Function RandomizeWords(ByVal text As String) As String
    Dim words As New List(Of String)(text.Split(" "c))
    Dim newwords As New List(Of String)
    For Each word As String In words
        newwords.Insert(r.Next(0, newwords.Count + 1), word)
    Next
    Return String.Join(" ", newwords.ToArray)
End Function
For example take 500 random picks from that "words" variable in example, remove the picked item as you go.

Thanks John!
Im stuck agian tho, here are the basics on how i'm trying to implement this code.

User opens a .txt file and the contents are sent to global variable "content1". Next the user enters in how many randomized words he wants in textbox "totalwords". All the above works with no errors, from here is where i need your help.

Once a numerical number is entered the user clicks "button12" and that button is to run that code you gave me, thus jumbling whats inside variable "content1" and taking out however many words was entered into the variable "totalwords". Once the code you gave me has jumbled up enough words to satisfy the number defined in "totalwords", the jumbled words are to be sent to a global variable named "scrambled1".

And thats it! The code you gave me works perfect, except for some reason i just cant link the "button12" to activate it and put the radomized words (matching the "totalwords" variable) into the global variable "scrambled1". Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-13-2008, 4:46 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Oct 2008
Age: 23
Posts: 1
Reputation: 0
OutRager- is on a distinguished programming path ahead
Default Random lenght of text also.

Hey there.

I want to hear if there is a way to do this so that it dosen't just mix up the word (ex. word to be mixed: hejlol end up like llojeh). I want to know if its possible to like only make words with 3 letters or 4 and so on. Like word to be mixed: helloa ends up like lol or hello so that it makes many different words in different lenght's?

Hope you know what i mean :-)

Kind Regards
OutRager-
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-13-2008, 6:08 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.0 (VS 2005/2008)
 
Join Date: Oct 2008
Posts: 5
Reputation: 0
matty is on a distinguished programming path ahead
Default

Quote:

For example take 500 random picks from that "words" variable in example, remove the picked item as you go.
Hey John,

I've figured out the rest to my last question, but i'm still bangin my head on trying to "pick" x amount of words out of the "words" variable. Any suggestions? Thanks!
Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-14-2008, 6:07 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 36
Posts: 9,163
Reputation: 1079
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

matty, learn how to use a For-Next loop.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 6:27 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0


For advertising opportunities click here.