473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pig latin program

i got my pig latin program which looks like this
Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
strInput = txtenglish.Text
str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
strOutput = strInput & "WAY"
Else
stranswer = txtanswer.Text
intStringLength = Len(strInput) - 1
strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
stranswer = strOutput

i was wondering why it won't show the results in the 2nd text output box(stranswer)

thank you
Nov 5 '07 #1
14 3076
Plater
7,872 Expert 4TB
Oh VB, how I dislike you....

Anyways, it looks like you only set the output stuff if it doesn't start with a vowel?

Expand|Select|Wrap|Line Numbers
  1. Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
  2. strInput = txtenglish.Text
  3. str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
  4. If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
  5. strOutput = strInput & "WAY"
  6. Else
  7. stranswer = txtanswer.Text
  8. intStringLength = Len(strInput) - 1
  9. strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
  10. stranswer = strOutput
  11.  

I'd do this:?
C#
Expand|Select|Wrap|Line Numbers
  1. private string EnglishWordToPigLatinWord(string EnglishWord)
  2. {
  3.    string retval="";
  4.    if (EnglishWord.Length > 0)
  5.    {
  6.       char FirstLetter=EnglishWord.ToUpper()[0];
  7.       if ((FirstLetter='A')||(FirstLetter='E')||(FirstLetter='I')||(FirstLetter='O')||(FirstLetter='U'))
  8.       {
  9.          retval=EnglishWord+"way";
  10.       }
  11.       else
  12.       {//regular
  13.          retval=EnglishWord.SubString(1);
  14.          retval+=EnglishWord[0]+"ay";
  15.       }
  16.    }
  17.    else
  18.    {
  19.       retval=EnglishWord;
  20.    }
  21.    return retval;
  22. }
  23.  
Nov 5 '07 #2
balabaster
797 Expert 512MB
Oh VB, how I dislike you....

Anyways, it looks like you only set the output stuff if it doesn't start with a vowel?

Expand|Select|Wrap|Line Numbers
  1. Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
  2. strInput = txtenglish.Text
  3. str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
  4. If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
  5. strOutput = strInput & "WAY"
  6. Else
  7. stranswer = txtanswer.Text
  8. intStringLength = Len(strInput) - 1
  9. strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
  10. stranswer = strOutput
  11.  
You could've cut down your typing by using a case statement there...you probably wouldn't dislike VB so much :P

Select Case str1stCharacter.ToUpper
Case "A", "E", "I", "O", "U" : 'Do your stuff
Case Else : 'Do different stuff
End Select
Nov 5 '07 #3
Plater
7,872 Expert 4TB
You could've cut down your typing by using a case statement there...you probably wouldn't dislike VB so much :P
I dislike VB for a whole mess of reasons, one of which is that VB on a whole, is a mess.
Nov 5 '07 #4
balabaster
797 Expert 512MB
I dislike VB for a whole mess of reasons, one of which is that VB on a whole, is a mess.
And that is a debate that will go on between VB programmers and C# programmers until the end of time ;) I come from both camps...I hate inheriting people's C# code but am quite comfortable writing my own. If I inherit someone else's code, I'd much rather it was VB. It's like reading English instead of reading Math...
Nov 5 '07 #5
Plater
7,872 Expert 4TB
I'd much rather it was VB. It's like reading English instead of reading Math...
That was my exact argument, only in reverse lol. dim stdTersadf makes less sence to me then "Int32 myint"
(and yes I made those variable names to follow the programming style I see on these boards)
As a side note, I "started" in VB as well.


But on the matter at hand, did that piglatin thing work correctly?
Nov 5 '07 #6
sorry , I'm a beginner at visual basics.
so far i have this.
Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
strInput = txtenglish.Text
str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
strOutput = strInput & "WAY"

Else
stranswer = txtanswer.Text
intStringLength = Len(strInput) - 1
strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
stranswer = strOutput

2 text
1 for english input(txtenglish)
and 1 for piglatin output(txtanswer)
so how come when i press compute
it doesn't show up in output
sorry if this annoys anyone
i'm just a beginner
Nov 6 '07 #7
Plater
7,872 Expert 4TB
This line:
stranswer = txtanswer.Text

sets stranswer to be whatever value is stored in txtanswer.Text
Not the other way around.
Try this:
txtanswer.Text=stranswer


Also, you need to make sure code gets execute in the right order.
They execute top to bottom. So if you set txtanswer.Text=stranswer then change the value of stranswer, the value in txtanswer.Text will NOT change unless you set it again with txtanswer.Text=stranswer
Nov 6 '07 #8
Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
strInput = txtinput.Text
str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
strOutput = strInput & "WAY"
Else
intStringLength = Len(strInput) - 1
strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
strOutput = stranswer
txtoutput.Text = stranswer

i've left it like this and it still doesn't work
damn
Nov 7 '07 #9
balabaster
797 Expert 512MB
Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As Integer
strInput = txtinput.Text
str1stCharacter = Microsoft.VisualBasic.Left(strInput, 1)
If str1stCharacter = "A" Or str1stCharacter = "E" Or str1stCharacter = "I" Or str1stCharacter = "O" Or str1stCharacter = "U" Then
strOutput = strInput & "WAY"
Else
intStringLength = Len(strInput) - 1
strOutput = Microsoft.VisualBasic.Right(strInput, intStringLength) & str1stCharacter & "WAY"
strOutput = stranswer
txtoutput.Text = stranswer

i've left it like this and it still doesn't work
damn
Well aside from the obvious:
Missing End If

I can't believe this question is still going round in circles :oP
Expand|Select|Wrap|Line Numbers
  1.  Dim str1stChar, strInput As String 
  2. strInput = txtInput.Text
  3. str1stChar = txtInput.Text.Substring(0, 1)
  4. Dim strOutput As String = ""
  5. Select Case str1stChar.ToUpper
  6. Case "A", "E", "I", "O", "U"
  7.     strOutput = strInput.ToUpper
  8. Case Else
  9.     strOutput = (strInput.Substring(1) & str1stChar).ToUpper
  10. End Select
  11. strOutput &= "WAY"
  12. txtOutput.Text = strOutput
Use this code...it works.
Nov 7 '07 #10
balabaster
797 Expert 512MB
Well aside from the obvious:
Missing End If

I can't believe this question is still going round in circles :oP
Expand|Select|Wrap|Line Numbers
  1. Dim str1stChar, strInput As String 
  2. strInput = txtInput.Text
  3. str1stChar = txtInput.Text.Substring(0, 1)
  4. Dim strOutput As String = ""
  5. Select Case str1stChar.ToUpper
  6. Case "A", "E", "I", "O", "U"
  7.     strOutput = strInput.ToUpper
  8. Case Else
  9.     strOutput = (strInput.Substring(1) & str1stChar).ToUpper
  10. End Select
  11. strOutput &= "WAY"
  12. txtOutput.Text = strOutput
Use this code...it works.
And actually, in the immortal words of Luca Bolognese, "there is something displeasing with this code", what if we do:
Expand|Select|Wrap|Line Numbers
  1. Function IsVowel(ByVal InputChar As Char) As Boolean
  2.   Dim Vowels() As Char = {"A", "E", "I", "O", "U"}
  3.   Return Not Array.IndexOf(Vowels, InputChar) = -1
  4. End Function
  5.  
  6. Dim strInput As String = txtInput.Text.ToUpper
  7. Dim strOutput As String = strInput
  8. Dim str1stChar As Char = strInput.Substring(0, 1)
  9. If IsVowel(str1stChar) Then strOutput = strInput.Substring(1) & str1stChar
  10. strOutput &= "WAY"
  11. txtOutput.Text = strOutput
There...that's much more elegant...and more flexible, you can add any items you want to the char array for your 1st char without having to do "OR str1stChar = "n" OR str1stChar = "r" etc etc
Nov 7 '07 #11
balabaster
797 Expert 512MB
And actually, in the immortal words of Luca Bolognese, "there is something displeasing with this code", what if we do:
Expand|Select|Wrap|Line Numbers
  1. Function IsVowel(ByVal InputChar As Char) As Boolean
  2.   Dim Vowels() As Char = {"A", "E", "I", "O", "U"}
  3.   Return Not Array.IndexOf(Vowels, InputChar) = -1
  4. End Function
  5.  
  6. Dim strInput As String = txtInput.Text.ToUpper
  7. Dim strOutput As String = strInput
  8. Dim str1stChar As Char = strInput.Substring(0, 1)
  9. If IsVowel(str1stChar) Then strOutput = strInput.Substring(1) & str1stChar
  10. strOutput &= "WAY"
  11. txtOutput.Text = strOutput
There...that's much more elegant...and more flexible, you can add any items you want to the char array for your 1st char without having to do "OR str1stChar = "n" OR str1stChar = "r" etc etc
Damnit, now I find myself keep coming back to this question pitting myself against it to try and get it down to as few lines of code as possible! It's like othello...a minute to learn, a lifetime to master...I feel a competition coming on. Who can achieve this in as few lines of code as possible?
Expand|Select|Wrap|Line Numbers
  1. Function IsVowel(ByVal InputChar As Char) As Boolean
  2.   Return Not Array.IndexOf(New Char() {"A", "E", "I", "O", "U"}, InputChar) = -1
  3. End Function
  4.  
  5. Dim strInput As String = txtInput.Text.ToUpper
  6. Dim strOutput As String = strInput
  7. Dim str1stChar As Char = strInput.Substring(0, 1)
  8. If IsVowel(str1stChar) Then strOutput = strInput.Substring(1) & str1stChar
  9. strOutput &= "WAY"
  10. txtOutput.Text = strOutput
Nov 7 '07 #12
balabaster
797 Expert 512MB
Damnit, now I find myself keep coming back to this question pitting myself against it to try and get it down to as few lines of code as possible! It's like othello...a minute to learn, a lifetime to master...I feel a competition coming on. Who can achieve this in as few lines of code as possible?
Expand|Select|Wrap|Line Numbers
  1. Function IsVowel(ByVal InputChar As Char) As Boolean
  2. Return Not Array.IndexOf(New Char() {"A", "E", "I", "O", "U"}, InputChar) = -1
  3. End Function
  4.  
  5. Dim strInput As String = txtInput.Text.ToUpper
  6. Dim strOutput As String = strInput
  7. Dim str1stChar As Char = strInput.Substring(0, 1)
  8. If IsVowel(str1stChar) Then strOutput = strInput.Substring(1) & str1stChar
  9. strOutput &= "WAY"
  10. txtOutput.Text = strOutput
Or you could do it in two lines. It's not quite as easy to read though...
VB
Expand|Select|Wrap|Line Numbers
  1. Dim strInput As String = txtInput.Text.ToUpper
  2. txtOutput.Text = (IIf(Array.IndexOf(New Char() {"A", "E", "I", "O", "U"}, CChar(strInput.Substring(0,1))) = -1, strInput.Substring(1) & strInput.Substring(0, 1), strInput) & "WAY").ToUpper()
I don't think I can reasonably cut it down any further than that...Ben 1-0 VB.NET :D

My work here is done...
Nov 8 '07 #13
Plater
7,872 Expert 4TB
Or you could do it in two lines. It's not quite as easy to read though...
VB
Expand|Select|Wrap|Line Numbers
  1. Dim strInput As String = txtInput.Text.ToUpper
  2. txtOutput.Text = (IIf(Array.IndexOf(New Char() {"A", "E", "I", "O", "U"}, CChar(strInput.Substring(0,1))) = -1, strInput.Substring(1) & strInput.Substring(0, 1), strInput) & "WAY").ToUpper()
I don't think I can reasonably cut it down any further than that...Ben 1-0 VB.NET :D

My work here is done...
What if you changed all references of "strinput" to "txtInput.Text.ToUpper"
Then it would be one line?
Nov 8 '07 #14
balabaster
797 Expert 512MB
What if you changed all references of "strinput" to "txtInput.Text.ToUpper"
Then it would be one line?
I thought hard about that one...I was going to, but then I have a rule of thumb that if I'm going to need to reference a property of an object more than once that I store that property in a variable because it lessens the code...here we reference it a whole bunch of times. Now in VB 2008 type inferencing you could scrap the "As String" which cuts it down a bit more, but I don't think (at least as far as keystrokes) it can be cut down further without changing to a shorter variable name such as sIn instead of strInput.
Nov 8 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Markus Ernst | last post by:
Hi I wrote a function that "normalizes" strings for use in URLs in a UTF-8 encoded content administration application. After having removed the accents from latin characters I try to remove all...
9
by: Andy | last post by:
I am trying to write a for loop that will print all the ISO-Latin characters to a database. However: I am not sure exactly how to go about printing the ISO-Latin character set. Would anyone be...
10
by: ahoway | last post by:
I am having problems entering a sentence for translating into pig latin. It is set up now to read the entire sentence as one word. I would like to know how to look at each word in the sentence so...
1
by: Chris Curvey | last post by:
Hey all, I'm trying to write something that will "fail fast" if one of my users gives me non-latin-1 characters. So I tried this: u'\x80' I would have thought that that should have raised...
3
by: MaStA | last post by:
I have to build a pig latin converter. It isn't an in depth one that needs to care about vowels, punctuation, etc. All it has to do is simply receive a sentence, break up the words, move the first...
5
by: johnmac | last post by:
I'm trying to make an english to pig latin program and it doesn't seem to show my output in my answer.text box Dim strInput, str1stCharacter, strOutput, stranswer As String, intStringLength As...
3
by: Sejoro | last post by:
Hey again, I'm trying to write a program that will output a random valid Latin Square (9x9 square of numbers 1 - 9 with no repetition in the rows and columns) and can't get my numbers to not...
7
by: schrum312005 | last post by:
Hey guys, I'm a college student in my first programming class and I'm having trouble with an assignment. The requirements to the assignment can be found here:...
14
by: berky | last post by:
I am so very close to making this program happen, however I am running into an error with single character words. When My program runs, if I put a single letter word in like A or I then...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.