Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.Net Coding Challenge #1
#31
(04-16-2011, 11:05 PM)KoBE Wrote: Yea, with out the dash it's almost impossible to know whether you took two characters from the front or just one. Also even with the dash... if you have a word like "work" it would be ork-way... but converting back it would be ork. Because ork translated to pig latin would be ork-way as well. This challenge definitely has some holes in it. But it still helps stimulate your programming/logic skills.

I finally got it working with a function that deals with no vowels like i've seen in online translators. for example, a no vowel text like "vkcd" would be "kcd-vay"

Where the v got moved after the hyphen and before the "ay" because it was just the first letter. If no vowels are found, my application will just take the first letter as shown, and do the same thing with it. I added onto your method for doing this as:

Definining noVowels:
Code:
Dim noVowels As String

Making the function for that string:
Code:
noVowels = strWord.Substring(1, 1)
strSplit = strWord.Substring(0, 1).ToLower
strResult = strWord.Substring(1, strWord.Length - 1) & "-" & strSplit & "ay"
Return strResult

Where I had assigned "i" the value of 1

The method for coding my translator was pretty much very similar to yours, where I had defined a string array for each letter (Vowels) as a,e,i,o,u, and added y. Then made the rules for appending and removing certain letters in a loop that scans all words in the input
Reply
#32
(04-16-2011, 11:40 PM)Infinity Wrote: The method for coding my translator was pretty much very similar to yours, where I had defined a string array for each letter (Vowels) as a,e,i,o,u, and added y. Then made the rules for appending and removing certain letters in a loop that scans all words in the input

Nice. Yeah I guess I didn't think about non-vowel words. I actually never knew one existed in the English language until you posted that one. But to add that functionality in I guess wouldn't be hard. If the word doesn't contain a vowel, put the first letter on the end and append 'ay". Seems logical! This challenge made me think a little bit.
Reply
#33
(04-16-2011, 11:49 PM)KoBE Wrote: Nice. Yeah I guess I didn't think about non-vowel words. I actually never knew one existed in the English language until you posted that one. But to add that functionality in I guess wouldn't be hard. If the word doesn't contain a vowel, put the first letter on the end and append 'ay". Seems logical! This challenge made me think a little bit.

Yeah, for me too, I haven't coded in vb for a while actually, did a couple short projects here and there but this made me realize how rusty i've gotten lol. I will be practicing some more of the basic fundamentals soon. I added a few more bonus features in my application to test a couple things out as well, as well as a customized class theme.

Update: @The High Roller, your program doesn't copy out the string from the output text box to the clipboard, it will copy out "End If" instead. Try it for yourself, but you may want to fix that.

Only thing i'm getting now is errors when I have only spaces in my code, and text inputs that have only one letter, and are not part of the string array for the vowels. Otherwise I have a fully functional PigLatin translator..
Reply
#34
Here's my entry, although it definitely isn't the best since there's still some things that need fixing in it. I'm working on that, and hopefully when I get them fixed, i'll re-upload soon.

Direct Download:
Pig Latin Translator v1.0

[Image: unledkx.png]
Reply
#35
(04-17-2011, 12:01 AM)Infinity Wrote: Only thing i'm getting now is errors when I have only spaces in my code, and text inputs that have only one letter, and are not part of the string array for the vowels. Otherwise I have a fully functional PigLatin translator..

Use simple validation for the spaces.
if(textBox1.Text.Trim() == String.Empty)
return true; //If there is only spaces or nothing at all it will return true

Although I use this in java not sure if it works in vb. Tongue
Should be something similar.

If TextBox1.Text.Trim() = "" Then
MessageBox.Show("Please enter text to translate")
End If
[Image: burninglove4.png]
Reply
#36
I would have used

Code:
If Textbox1.Text.Trim = 0 Then

Or maybe:

Code:
If Textbox1.Text.StartsWith(" ") Then

Those are the 2 I thought of

UPDATE:

Haha, I created a code that worked, I added:
Code:
If TextBox1.Text.Trim.Length = 0 Then
            MsgBox("You must type something into the input textbox field in order to translate.", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
        End If

Update: I also made it so that "A" is the only single character you can input into the original text field to translate since it's the only singular letter word in the english language.

Code:
ElseIf TextBox1.Text = "a" Then
            TextBox2.Text = "a-way"
        ElseIf TextBox1.Text.Length = 1 Then
            MsgBox("There was an error while trying to translate the input text. Please try again or make sure you spelled it correctly", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
        End If

"A" to PigLatin in my application will translate to: "a-way"
and if you select "A" to translate to english it will translate to: "A"

I'm going to update my download link soon... I worked for a while on such a useless app lol Smile

Direct Download:
Pig Latin Translator v1.0

Full Source:
Code:
Public Class Form1

    'Checks to whether or not you want your form topmost property active or not. Your window will appear above all others if it is checked
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        'If Checkbox is checked then topmost is active
        If CheckBox1.Checked Then
            Me.TopMost = True
            'If Checkbox is not checked then topmost is inactive
        ElseIf CheckBox1.Checked = False Then
            Me.TopMost = False
        End If
    End Sub

    'When clicked take me to supportforums.net in my default web browser
    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        System.Diagnostics.Process.Start("http://www.supportforums.net")
    End Sub

    Private Sub FButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
        'This will clear the textbox everytime you hit the button so that the new string value can replace the original converted text without having the press the clear button
        TextBox2.Text = ""

        If TextBox1.Text.Trim.Length = 0 Then
            MsgBox("Cannot translate only spaces in the input text field", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
        ElseIf TextBox1.Text = "a" Then
            TextBox2.Text = "a-way"
        ElseIf TextBox1.Text.Length = 1 Then
            MsgBox("There was an error while trying to translate the input text. Please try again or make sure you spelled it correctly", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
        ElseIf TextBox1.Text.StartsWith(" ") Then
            MsgBox("There was an error while trying to translate the input text. You may have a space in front of your input text. Please remove the space and try again", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
        End If

        'Convert To PigLatin >
        If RadioButton1.Checked = True Then
            'Checks to make sure textbox field is not empty
            If TextBox1.Text = "" Then
                MsgBox("Please type in your text to translate before proceeding", MsgBoxStyle.Information, "Information - PigLatin Translator v1.0")
                Exit Sub
            ElseIf TextBox1.Text.Contains("-") Then
                MsgBox("The input text is already in PigLatin. Please change it to translate to English, or try typing in something else", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Else
                'splits the entire text into  indivisdual words for the loop to use the function (Convert_PigLatin) to all words before putting it into the output text field

                'Separates or splits each word in the loop with a space
                Dim strWords() As String = TextBox1.Text.Split(" ")
                For i = 0 To strWords.Length - 1
                    'this loops through each word converting it to pig-latin
                    strWords(i) = Convert_PigLatin(strWords(i))
                Next
                'after each word is converted, it joins the string together and seperates
                'each word by a space
                TextBox2.Text = Join(strWords, " ")
            End If

        End If

        'Convert to English >
        If RadioButton2.Checked = True Then
            'Without "-" Give output textbox value the same as the input text field string, and show messagebox with error
            If Not TextBox1.Text.Contains("-") Then
                TextBox2.Text = TextBox1.Text
                MsgBox("Could not translate to English. Please check to make sure that you have entered your text in proper PigLatin or that you haven't entered in English by accident. The translated text may or may not be translated to English.", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
                Exit Sub
            Else
                'Puts each word into a string array
                Dim strWords() As String = TextBox1.Text.Split(" ")
                For i = 0 To strWords.Length - 1
                    'Translate each word with the loop
                    strWords(i) = Convert_English(strWords(i))
                Next
                'join each translated word back to a sentence separated by a space " "
                TextBox2.Text = Join(strWords, " ")
            End If
        End If
    End Sub

    Private Function Convert_PigLatin(ByVal strWord As String) As String

        Dim VowelList As Char        'Finds the first vowel
        Dim noVowels As String      'For if there is no Vowels in the wor
        Dim SplitText As String      'Takes the first letters before the first vowel and appends it after a hyphen
        Dim TextResult As String     'Translated string value to be displayed in output text field
        Dim iIndex As Integer       'Splits the text by the voweld
        For i = 0 To strWord.Length - 1

            'Loop through each character to find the first vowel in the word
            VowelList = strWord.Substring(i, 1)
            Select Case VowelList.ToString.ToLower
                'Defines our Vowels to search for, "Y" has been added in this case in addition to the normal Vowels
                Case "a", "e", "i", "o", "u", "y"
                    'If vowel is the first character (0 means it's the first in this loop) return input text string value (strWord) and append -way to the end
                    If i = 0 Then Return strWord & "-way"
                    'strSplit is what gets added to the end of the word
                    SplitText = strWord.Substring(0, i).ToLower
                    'This is just the location of the first vowel in the word
                    iIndex = strWord.IndexOf(VowelList)
                    'Makes the output start with the first vowel found in the loop for the word, followed by the "-", then the characters taken from the beginning
                    'Before the vowel (strSplit), and append 'ay' at the end.
                    TextResult = strWord.Substring(iIndex, strWord.Length - iIndex) & "-" & SplitText & "ay"
                    'Return the translated word (strResult) is what goes into The output text field for the converted words.
                    Return TextResult
                    Exit For
            End Select
        Next
        'If there are no vowels in the input text field, take the original string value, and find the second letter in the word (1)
        noVowels = strWord.Substring(1, 1)
        SplitText = strWord.Substring(0, 1).ToLower
        'Text result as original input subtracting the first letter in the string, Appending "-", "the first split letter, and "ay" on the end.
        TextResult = strWord.Substring(1, strWord.Length - 1) & "-" & SplitText & "ay"
        Return TextResult

    End Function

    Private Function Convert_English(ByVal strWord As String) As String
        Dim iIndex As Integer = strWord.IndexOf("-")            'Reports the first "-" that it finds in the string value to find where the split is
        Dim iLastIndex As Integer = strWord.IndexOf("ay")       'Finds original moved text that got added in between "-" and "ay" in the result
        Dim TextResult As String                                 'The result that gets displayed as the translated text
        If strWord.Substring(iIndex + 1, 1).ToLower = "w" Then
            'If the first letter after the index of "-" happens to be a w, then chances are it's "-way" and it will be removed
            TextResult = strWord.Remove(iIndex)
        Else
            'Moves the letters between '-' and 'ay' and adds it to the front of the string result. Removing "-" and "ay"
            TextResult = strWord.Substring(iIndex + 1, iLastIndex - iIndex - 1) & strWord.Substring(0, iIndex)
        End If
        'Show Translated string (Returns that value)
        Return TextResult
    End Function


    Private Sub FButton3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton3.Click
        'One of the easiest codes in VB. close/end the application ;)
        End
    End Sub

    Private Sub FButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton2.Click
        'Clears all of the text in The output Textbox, (Not needed though)
        TextBox2.Text = ""
    End Sub

    Private Sub FButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton4.Click
        'If TextBox2 is not empty Then execute the code
        If Not TextBox2.Text = "" Then
            Clipboard.SetText(TextBox2.Text)
            Dim CopyText As String = Clipboard.GetText 'This assigns text to clipboard
            'Message for confirmation
            MsgBox("Your text has been successfully copied to the clipboard!", MsgBoxStyle.Information, "Information - PigLatin Translator v1.0")
            'Otherwise, if the textbox area is empty, show this message...
        Else : MsgBox("Sorry, there is no text to copy to the clipboard. Please try translating an input text to either English or Piglatin and try again.", MsgBoxStyle.Information, "Information - PigLatin Translator v1.0")
        End If
    End Sub

End Class

I noticed that it wasn't about anything other than getting people participating in the coding. But I noticed that both of you kept the same default icon for your project and other basic things like that. Always good practice to get into setting up your project though.
Reply
#37
(04-17-2011, 03:53 AM)Infinity Wrote: I noticed that it wasn't about anything other than getting people participating in the coding. But I noticed that both of you kept the same default icon for your project and other basic things like that. Always good practice to get into setting up your project though.

Your program is by far better than mine or The High Roller. You did a real good job on this. I did get lazy on appearance. Yours looks amazing though. The functionality is pretty good too.

I'm still looking at it, but I will edit this post if I find any errors besides the ones you mentioned. Good job. Thumbsup
Reply
#38
Everytime I enter a word with a hyphen it says it's already in pig latin. Tongue
[Image: burninglove4.png]
Reply
#39
(04-17-2011, 08:24 AM)Untouch Wrote: Everytime I enter a word with a hyphen it says it's already in pig latin. Tongue

By definition a word with a hyphen isn't a word anyway, it's a compound word, meaning it's 2 definitions. (Example: absent-minded). I know the rule is broken a lot and people can use words like "lifestyle" instead of "life-style," however both are acceptable, so they are really 2 words together, and not one word. The English language has changed a lot over time though, and we've made a lot of confusing exceptions.

Plus, there's not a real way that you can avoid that though. If you want to convert the word "Run-way" to PigLatin for example, "-way" is already a part of the code, and since "a" is the first vowel it would have to either write something like "un-way-ray" or give that error, since the conversion to english in that case is really to just remove "-way". I've taken a look at a whole bunch of different words with online Piglatin to English translators and it seems that a lot of them are different. I am able to remove that rule in the code if you guys think it's necessary, but I wasn't really sure that there was a true rule for the odd words like this. But i've tried looking up words with no vowels, words with one letter (which aren't really english words except for the letter "a"), etc.

Words that sound the same but with different meanings: (Example: Effect, and Affect get confused with each other a lot)

English is basically a mix of everything lol. It's actually quite the "unorganized" language, since so many rules are combined together, and is arguably one of the hardest languages to learn if it's not your first language, for that one reason.

I got rid of any errors for when you type in something like:

Code:
{space*any # of times}.... {letters}

(Anything with a space first will come out with a message as a critical error)

Update: I found another Error when you type in something like {letters}... {space* any # of times}
so I just recently added this to one of my if statements in the code:

Code:
ElseIf TextBox1.Text.EndsWith(" ") Then
            MsgBox("There was an error while trying to translate the input text. You may have a space at the end of your input text. Please remove the space and try again", MsgBoxStyle.Critical, "Error - PigLatin Translator v1.0")
            Exit Sub
Reply
#40
So I updated my submission... Infinity made his look bad ass so I had to too. I used a public GUI made by C4Vendetta. I also added cue text to the input text box.

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code Challenge - Created by Ace AceInfinity 5 1,706 04-24-2012, 10:27 AM
Last Post: AceInfinity
  Help with coding jerrojack 1 877 12-29-2011, 03:27 AM
Last Post: AceInfinity
  Coding-Central.net - Coding, cracking and webmastering. w00pz 5 2,432 09-02-2011, 01:43 PM
Last Post: AceInfinity
  Help Coding A Downloader? Fragma 9 3,423 08-25-2011, 06:10 PM
Last Post: LiveModz
  .Net Coding Challenge #5 iCrack 18 5,906 05-21-2011, 12:49 AM
Last Post: thanasis2028

Forum Jump:


Users browsing this thread: 2 Guest(s)