Pig Latin

I am stuck

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 3382 Views - Last Post: 11 April 2009 - 09:15 PM Rate Topic: -----

#1 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Pig Latin

Post icon  Posted 05 April 2009 - 01:47 PM

Hi
I am stuck on how to deal with the last part of this problem. Words that begin with a consonant- you take the consanant place it at the end and add "ay" like chair will be airchay and toy will be oytay, then if it is numeric we simply add "-way" to the end of the expression like "56-way"

The code below seems to work fine for any word that begins with a vowel, although I feel I have non-essential code probably.
I cannot picture how to solve the last part of the issue with consonants and numerics. I am unsure which way is best to solve the problem and I cannot figure out how to move the single or double consonants to the back of the word...i do not see how we just learned beginner string manipulations such as mid, replace, remove, trim, contains, indexof, startswith, endswith and the insert method. I am using VB express.
I would appreciate help with code but if you have time I would really appreciate explanations as to the choice of code to help me understand why one way worksbest and so on.

thanks
Gail

'Gail Amalfitano
'date modified 4/1/09
'This program is for converting words or strings to pig latin. The user enters what they want converted,
'hits the converter button and views the pig latin version of their entry.

Option Explicit On
Option Strict On
Option Infer Off


Public Class mainForm

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()

    End Sub

    Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

        'declare variable
        Dim originalWord As String
        Dim vowels As String() = {"a", "A", "e", "E", "i", "I", "o", "O", "u", "U", "y", "Y"}
        Dim pigLatin As String
        Dim containsVowel As Boolean = False


        'assign user input to variable
        originalWord = entryTextBox.Text.Trim

        'determine what the word starts with
        If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
            pigLatin = originalWord & "way"

            'display original word with vowel as piglatin word
            displayLabel.Text = pigLatin

        Else
            pigLatin = originalWord.mid(
        End If
        

    End Sub

    Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click
        'clears all label data

        displayLabel.Text = String.Empty
        entryTextBox.Text = String.Empty
    End Sub

End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Pig Latin

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,520
  • Joined: 23-August 08

Re: Pig Latin

Posted 05 April 2009 - 02:21 PM

Moving to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#3 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Pig Latin

Posted 05 April 2009 - 03:31 PM

moving the first letter to end is simple enough with concatenation
String = mid(varMytext,2) & left(varMytext,1) & "ay"


This post has been edited by June7: 05 April 2009 - 07:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 05 April 2009 - 08:04 PM

View PostJune7, on 5 Apr, 2009 - 02:31 PM, said:

moving the first letter to end is simple enough with concatenation
String = mid(varMytext,2) & left(varMytext,1) & "ay"




hello
the method "left" is not recognized, when i tried this code the "left" gave an error. The problem is I do not undestand how to move one or two letters from begining to end. this is my first semester with VB.
thanks for trying
Gail
Was This Post Helpful? 0
  • +
  • -

#5 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 05 April 2009 - 08:24 PM

I have touched up my code some but still cannot get the last 2 rules to work. I am not sure if using a for/next will work or a case select is better.
last 2 rules are if word begins with consonant take consonant put on end add "ay" with the single or double consonant, or if numeric add "-way" to end.


Public Class mainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()

	End Sub

	Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

		'declare variable
		Dim originalWord As String
		Dim pigLatin As String



		'assign user input to variable
		originalWord = entryTextBox.Text.Trim

		'determine what the word starts with
		'display original word with vowel as piglatin word
		If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
			pigLatin = originalWord & "way"
			displayLabel.Text = pigLatin

		Else
			'display original word with consonant as piglatin word
			pigLatin = Mid(originalWord, 2) & "ay"
			displayLabel.Text = pigLatin

		 End If
		
		entryTextBox.Focus()
	End Sub

	Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click

		'clears all label data
		displayLabel.Text = String.Empty
		entryTextBox.Text = String.Empty
	End Sub

	Private Sub entryTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.Enter

		'selects text in textBox
		entryTextBox.SelectAll()
	End Sub

	Private Sub entryTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.TextChanged

		'clears display label when new text is typed
		displayLabel.Text = String.Empty
	End Sub
End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#6 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 05 April 2009 - 08:49 PM

quote name='wingspegasus' date='5 Apr, 2009 - 07:24 PM' post='596328']
I have touched up my code some but still cannot get the last 2 rules to work. I am not sure if using a for/next will work or a case select is better.
last 2 rules are if word begins with consonant take consonant put on end add "ay" with the single or double consonant, or if numeric add "-way" to end.


Public Class mainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()

	End Sub

	Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

		'declare variable
		Dim originalWord As String
		Dim pigLatin As String



		'assign user input to variable
		originalWord = entryTextBox.Text.Trim

		'determine what the word starts with
		'display original word with vowel as piglatin word
		If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
			pigLatin = originalWord & "way"
			displayLabel.Text = pigLatin

		Else
			'display original word with consonant as piglatin word
			pigLatin = Mid(originalWord, 2) & "ay"
			displayLabel.Text = pigLatin

		 End If
		
		entryTextBox.Focus()
	End Sub

	Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click

		'clears all label data
		displayLabel.Text = String.Empty
		entryTextBox.Text = String.Empty
	End Sub

	Private Sub entryTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.Enter

		'selects text in textBox
		entryTextBox.SelectAll()
	End Sub

	Private Sub entryTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.TextChanged

		'clears display label when new text is typed
		displayLabel.Text = String.Empty
	End Sub
End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
[/quote]





Public Class mainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()

	End Sub

	Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

		'declare variable
		Dim originalWord As String
		Dim pigLatin As String



		'assign user input to variable
		originalWord = entryTextBox.Text.Trim

		'determine what the word starts with
		'display original word with vowel as piglatin word
		If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
			pigLatin = originalWord & "way"
			displayLabel.Text = pigLatin

		Else
			'display original word with consonant as piglatin word
			pigLatin = Mid(originalWord, 2) & "ay"
			displayLabel.Text = pigLatin

		 End If
		
		entryTextBox.Focus()
	End Sub

	Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click

		'clears all label data
		displayLabel.Text = String.Empty
		entryTextBox.Text = String.Empty
	End Sub

	Private Sub entryTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.Enter

		'selects text in textBox
		entryTextBox.SelectAll()
	End Sub

	Private Sub entryTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.TextChanged

		'clears display label when new text is typed
		displayLabel.Text = String.Empty
	End Sub
End Class


Quote

I do not understand, this is my first post do I type that in or use the "code" button, or is it like html where you use "/code" at the end

Was This Post Helpful? 0
  • +
  • -

#7 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 05 April 2009 - 08:55 PM

Quote

okay , I see how to do it now.


'Gail Amalfitano
'date modified 4/5/09
'This program is for converting words or strings to pig latin. The user enters what they want converted,
'hits the converter button and views the pig latin version of their entry.

Option Explicit On
Option Strict On
Option Infer Off


Public Class mainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()

	End Sub

	Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

		'declare variable
		Dim originalWord As String
		Dim pigLatin As String



		'assign user input to variable
		originalWord = entryTextBox.Text.Trim

		'determine what the word starts with
		'display original word with vowel as piglatin word
		If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
			pigLatin = originalWord & "way"
			displayLabel.Text = pigLatin
		ElseIf originalWord.Substring(0, 1) Like "[0-9]" Then
			pigLatin = originalWord & "-way"
			displayLabel.Text = pigLatin

		Else
			'display original word with consonant as piglatin word
			pigLatin = Mid(originalWord, 2) & "ay"
			displayLabel.Text = pigLatin

		 End If
		
		entryTextBox.Focus()
	End Sub

	Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click

		'clears all label data
		displayLabel.Text = String.Empty
		entryTextBox.Text = String.Empty



Was This Post Helpful? 0
  • +
  • -

#8 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Pig Latin

Posted 06 April 2009 - 02:49 AM

Apologies, I do most of my coding in VBA for Access and sometimes forget VB6 and VB.Net have some variations. If the left function won't work but mid does, use mid in its place.

In VBA, it would be
String = mid(varMyText,2) & mid(varMyText,1,1) & "ay"


Modify as needed for equivalent VB structure. I don't have my VB books handy but am curious so will check at work later.

Edit: Just referenced my Murach. Both Mid and Left are functions available in VB.Net and the ampersand (&) is concatenation character. So my original and second suggestions should both work for you as they do for me.

This post has been edited by June7: 06 April 2009 - 12:10 PM

Was This Post Helpful? 1
  • +
  • -

#9 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 06 April 2009 - 04:12 PM

View PostJune7, on 6 Apr, 2009 - 01:49 AM, said:

Apologies, I do most of my coding in VBA for Access and sometimes forget VB6 and VB.Net have some variations. If the left function won't work but mid does, use mid in its place.

In VBA, it would be
String = mid(varMyText,2) & mid(varMyText,1,1) & "ay"


Modify as needed for equivalent VB structure. I don't have my VB books handy but am curious so will check at work later.

Edit: Just referenced my Murach. Both Mid and Left are functions available in VB.Net and the ampersand (&) is concatenation character. So my original and second suggestions should both work for you as they do for me.


Quote

thanks
this works now. I am still however stuck with the issue of words that begin with 2 consonants like chair. chair should convert to "air chay" or "airchay" but I do not know how to account for such things.
I thank you for your help!!!!! ;)
Gail

Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Pig Latin

Posted 06 April 2009 - 04:18 PM

View PostJune7, on 6 Apr, 2009 - 08:49 AM, said:

Apologies, I do most of my coding in VBA for Access and sometimes forget VB6 and VB.Net have some variations. If the left function won't work but mid does, use mid in its place.

A Clue on how to do Mid,Left & Right properly is in the Strings Tutorial

This post has been edited by AdamSpeight2008: 06 April 2009 - 04:20 PM

Was This Post Helpful? 1
  • +
  • -

#11 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 06 April 2009 - 04:32 PM

View PostAdamSpeight2008, on 6 Apr, 2009 - 03:18 PM, said:

View PostJune7, on 6 Apr, 2009 - 08:49 AM, said:

Apologies, I do most of my coding in VBA for Access and sometimes forget VB6 and VB.Net have some variations. If the left function won't work but mid does, use mid in its place.

A Clue on how to do Mid,Left & Right properly is in the Strings Tutorial



Quote

thanks
I appreciate the tips as well. I would like to understand how to manipulate these strings better. I do appreciate your time.
Gail

Was This Post Helpful? 0
  • +
  • -

#12 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 06 April 2009 - 04:54 PM

View Postwingspegasus, on 6 Apr, 2009 - 03:32 PM, said:

View PostAdamSpeight2008, on 6 Apr, 2009 - 03:18 PM, said:

View PostJune7, on 6 Apr, 2009 - 08:49 AM, said:

Apologies, I do most of my coding in VBA for Access and sometimes forget VB6 and VB.Net have some variations. If the left function won't work but mid does, use mid in its place.

A Clue on how to do Mid,Left & Right properly is in the Strings Tutorial



Quote

thanks
I appreciate the tips as well. I would like to understand how to manipulate these strings better. I do appreciate your time.
Gail




Quote

Okay here is my final code. I declare a variable that is not used yet. I am wondering if I need to use the index to somehow fix this issue with the consonants.
Maybe I need to nest another if, then or do some kind of comparison to figure out if the word begins with a consonant then tell it to move the consonants to the end

'you know something like this
determine if origninalWord begins with a consonant
determine how many consonants there are before you reach the first vowel
If originalWord begins with 1 consonant
Then move it to end & "ay"
Else If original word begins with 2 consonants
Then move 2 consonants to end and add & "ay"
Else If originalWord begins with 3 consonants
Then move 3 consonants to end & "ay"
displayLabel.Text = pigLatin

Else If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]"
Then pigLatin = originalWord & "-way"
displayLabel.Text = pigLatin
Else originalWord.Substring(0, 1) Like "[0-9]"
Then pigLatin = originalWord & "-way"
displayLabel.Text = pigLatin

But I do not know the proper way to code the begining in red color text the last two sections work for vowels and numbers.
anyway here is my new code.

Option Explicit On
Option Strict On
Option Infer Off


Public Class mainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()

	End Sub


	Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click

		'declare variable
		Dim originalWord As String
		Dim pigLatin As String
		Dim indexNum As Integer



		'assign user input to variable
		originalWord = entryTextBox.Text.Trim

		'determine what the word starts with a vowel, consonant, or numeric.
		'display original word with vowel as piglatin word add "-way" to end of word.
		'display original word with consonant as piglatin word take the consoanants until you reach the vowel, add
		'consonants to end of word with 'ay" added to end of consonants.
		'if words are numeric add "-way" to end of numeric expression.

		If originalWord.Substring(0, 1).ToUpper() Like "[AEIOU]" Then
			pigLatin = originalWord & "-way"
			displayLabel.Text = pigLatin
		ElseIf originalWord.Substring(0, 1) Like "[0-9]" Then
			pigLatin = originalWord & "-way"
			displayLabel.Text = pigLatin

		Else
			'this code below does not work if word has 2 or more begining consonants
			pigLatin = Mid(originalWord, 2) & Mid(originalWord, 1, 1) & "ay"
			displayLabel.Text = pigLatin

		End If

		entryTextBox.Focus()
	End Sub

	Private Sub resetButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles resetButton.Click

		'clears all label data
		displayLabel.Text = String.Empty
		entryTextBox.Text = String.Empty
	End Sub

	Private Sub entryTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.Enter

		'selects text in textBox
		entryTextBox.SelectAll()
	End Sub

	Private Sub entryTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles entryTextBox.TextChanged

		'clears display label when new text is typed
		displayLabel.Text = String.Empty
	End Sub
End Class



Well I hope someone can talk to me about this. The online class has no input from our instructor. She never gets into our online discusions/questions/posts and she never posts any tips or anything to help us out. So we are on our own with a book.
Gail

Was This Post Helpful? 0
  • +
  • -

#13 June7  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 104
  • View blog
  • Posts: 904
  • Joined: 09-December 08

Re: Pig Latin

Posted 06 April 2009 - 06:57 PM

After checking for vowel and number in position 1, check position 2 for consonant - use the Mid function. I am showing Iif (in-line If) statements but you could break up into multi-line IF THEN ELSE structure.

If .... Then		  'check for vowel in position 1
	...
elseif .... Then	 'check for number in position 1
	...
Else
	booConsonant = Iif(mid(myText,2,1) Like "[AEIOU]", False, True)
	String = mid(myText, Iif(booConsonant, 3, 2)) & Left(myText, Iif(booConsonant, 2, 1)) & "ay"
End If


The booConsonant is not essential but aids in readibility. The Iif for the booConsonant expression could be substituted in place of the two booConsonants in the String expression. In-line Ifs can become very long and confusing.

How would you handle situation if there is a number in any other position besides first or is that not a concern for this exercise? Need to handle words with three consonant beginnings like rhyme and rhythm and with thr beginning? Try building on what I've suggested so far.

This post has been edited by June7: 06 April 2009 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

#14 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 06 April 2009 - 08:13 PM

View PostJune7, on 6 Apr, 2009 - 05:57 PM, said:

After checking for vowel and number in position 1, check position 2 for consonant - use the Mid function. I am showing Iif (in-line If) statements but you could break up into multi-line IF THEN ELSE structure.

If .... Then		  'check for vowel in position 1
	...
elseif .... Then	 'check for number in position 1
	...
Else
	booConsonant = Iif(mid(myText,2,1) Like "[AEIOU]", False, True)
	String = mid(myText, Iif(booConsonant, 3, 2)) & Left(myText, Iif(booConsonant, 2, 1)) & "ay"
End If


The booConsonant is not essential but aids in readibility. The Iif for the booConsonant expression could be substituted in place of the two booConsonants in the String expression. In-line Ifs can become very long and confusing.

How would you handle situation if there is a number in any other position besides first or is that not a concern for this exercise? Need to handle words with three consonant beginnings like rhyme and rhythm and with thr beginning? Try building on what I've suggested so far.



Quote

Okay thanks
booconsonant is new to me as is Iif statement. But I will check this out. thanks sooooo much for the reply and help. 3 consonants is a problem. I was wondering is the select case structure would work for this.
okay let me get to work.

Was This Post Helpful? 0
  • +
  • -

#15 wingspegasus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-April 09

Re: Pig Latin

Posted 06 April 2009 - 08:31 PM

[quote]
VB express does not like this code I tried fixing it up but it almost worked...however for the words like boy, or yellow, it went too far and took the vowel with it to the end

for yellow it returned llowyeay, and boy it return yboay and toy = ytoay rather than toy=oytay, boy = oytay, yellow = ellowyay.

For now we do not have to worry about numbers inside the word. We just now learned basic string manipulations like, replace, trim, remove, starts with, indexOf, indsert and so on. We just got an intro to selection structures last week. So it is very basic so far.

Thanks
I was wondering if a case structure might work better.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2