Visual Basic .NET Forums  
Click here to advertise with us

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 08-29-2008, 1:39 PM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Aug 2008
Posts: 2
Reputation: 0
dazza666 is on a distinguished programming path ahead
Default Basic Word Jumber

Hi,
I'm very new to programming and i'm trying to create a word jumbler. The idea is someone types something in to a text box and a label displays the letters in a random order. I'm trying to use an array to ensure the same value doesn't appear twice can someone tell me where i'm going wrong?

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim rndNumber As Integer
        Dim arrRepeat(TextBox1.Text.Length) As Integer

        Dim store, txtCount, i As Integer



        Label2.Text = " "

      

        For txtCount = 1 To TextBox1.Text.Length

start:      Randomize()


            rndNumber = Int((Rnd()) * TextBox1.Text.Length)


            For store = 0 To TextBox1.Text.Length - 1

                If rndNumber = arrRepeat(store) Then

                    GoTo start


                End If


                arrRepeat(txtCount) = rndNumber
            Next store



        Next txtCount

        For i = 0 To TextBox1.Text.Length - 1



            Label2.Text = Label2.Text & TextBox1.Text.Chars((arrRepeat(i) + 1))
        Next






    End Sub
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-29-2008, 3:53 PM
VB.NET Forum Idol
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Feb 2008
Location: USA
Posts: 877
Reputation: 500
MattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond reputeMattP has a reputation beyond repute
Default

I'm hoping this isn't for a class but it does look like you've tried to research this (a little).

Code:
Imports System.Text

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click

        Dim WordArray() As String = Split(TextBox1.Text, " ")
        Dim Word() As Char
        Dim LetterPlaceholder As Char
        Dim WordCount As Integer
        Dim i As Integer
        Dim Position As Integer

        Dim sb As New StringBuilder()

        For WordCount = 0 To WordArray.Length - 1 'Cycle through array of strings

            If WordCount > 0 AndAlso WordCount <= WordArray.Length - 1 Then
                sb.Append(" ") 'Add space between word
            End If

            Word = WordArray(WordCount)

            For i = 0 To Word.Length - 1 'Cycle through each letter in a word
                Position = (Word.Length - 1) * Rnd() 'Swap with random position in string
                LetterPlaceholder = Word(Position) 'Store char to swap so it doesn't get lost
                Word(Position) = Word(i) 'Set current letter to with letter to swap
                Word(i) = LetterPlaceholder 'Set current letter with swapped letter
            Next

            sb.Append(Word) ' Add swapped word to string builder
        Next

        TextBox2.Text = sb.ToString()

    End Sub
End Class
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-29-2008, 8:11 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,328
Reputation: 1315
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

another suggestion...
Code:
Private Sub JumbleButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JumbleButton.Click
    Me.ResultLabel.Text = RandomizeWord(Me.InputTextBox.Text)
End Sub

Private r As New Random
Private Function RandomizeWord(ByVal word As String) As String
    Dim newword As String = String.Empty
    For Each c As Char In word
        newword = newword.Insert(r.Next(0, newword.Length + 1), c)
    Next
    Return newword
End Function
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-30-2008, 4:08 AM
VB.NET Forum Newbie
.NET Framework: .NET 1.1 (VS 2003)
 
Join Date: Aug 2008
Posts: 2
Reputation: 0
dazza666 is on a distinguished programming path ahead
Default

thats great thanks
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 3:13 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.