Alright so i'm writing a program, and i need to count the number of times a word begins with a letter. -
Public Class frmPigLatin
-
-
Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
-
Dim strChar1 As String
-
Dim strInput As String
-
Dim strOutput As String = ""
-
Dim strWords As String() 'Makes an empty array
-
Dim i As Integer
-
Dim strConversion As String
-
strInput = txtEnterWords.Text
-
-
'Split the text into an array of words
-
strWords = Split(strInput, " ")
-
-
For i = LBound(strWords) To UBound(strWords)
-
strChar1 = strWords(i).Substring(0, 1)
-
-
Select Case strChar1.ToUpper
-
Case "A", "E", "I", "O", "U"
-
strWords(i) = (strWords(i) & "WAY")
-
Case Else
-
strWords(i) = (strWords(i).Substring(1) & strChar1 & "AY")
-
End Select
-
-
'Loop through each word...
-
Next i
-
-
'Put the words back together.
-
strConversion = String.Join(" ", strWords)
-
MessageBox.Show(strConversion _
-
& vbCrLf & "There are " & nbrWords() & " words in the box.", "Pig Latin")
-
-
End Sub
-
-
Private Function nbrWords()
-
-
Dim strLength As String
-
Dim strWhole As String
-
Dim strCounter As String
-
Dim x As Integer
-
-
'Trim spaces on front and end.
-
strWhole = Trim(Me.txtEnterWords.Text)
-
If strWhole = "" Then
-
MsgBox("Please enter words")
-
End If
-
'Put the length of strWhole in the strLength variable
-
strLength = Len(strWhole)
-
strCounter = 1
-
-
Dim currentLetter As String
-
Dim prevLetter As String
-
-
For x = 2 To strLength
-
currentLetter = Mid(strWhole, x, 1)
-
prevLetter = Mid(strWhole, x - 1, 1)
-
If currentLetter = Chr(32) And prevLetter <> Chr(32) Then
-
strCounter = strCounter + 1
-
End If
-
-
Next
-
-
Return strCounter
-
-
End Function
-
Alright so now the message box displays the correct conversion to pig latin, and will count the number of words in the string, but i need to be pointed in the right direction as to how i could.
1. Count the number of words that begin with a vowel coming from the text box. I was looking around and learned how to count all the vowels in the string, but i dont know what i need to do to search the first char then skip the string and goto the next. Can anyone point me in the right direction?
9 1309
Is it possible to insert a counter in this line of code to count if the string begins with vowel while its being split up? -
'Split the text into an array of words
-
strWords = Split(strInput, " ")
-
-
For i = LBound(strWords) To UBound(strWords)
-
strChar1 = strWords(i).Substring(0, 1)
-
-
Select Case strChar1.ToUpper
-
Case "A", "E", "I", "O", "U"
-
strWords(i) = (strWords(i) & "WAY")
-
Case Else
-
strWords(i) = (strWords(i).Substring(1) & strChar1 & "AY")
-
End Select
-
-
'Loop through each word...
-
Next i
-
Wouldn't you just increment a numeric variable after, say, line 9?
sigh, thank you killer.. appreciate it.
sigh, thank you killer.. appreciate it.
The simple ones are surprisingly easy to miss, huh.
One more question if someone doesnt mind.
I'm trying to throw an exception if nothing is entered in the text box. The message is displayed once the translate button is clicked, but i need it to stop immediately before any output is given through the message box. And for some reason, focus won't work on my text box :/ -
Try
-
For i = LBound(strWords) To UBound(strWords)
-
-
strChar1 = strWords(i).Substring(0, 1)
-
-
Select Case strChar1.ToUpper
-
Case "A", "E", "I", "O", "U"
-
strWords(i) = (strWords(i) & "WAY")
-
intCountVowel = intCountVowel + 1
-
-
Case Else
-
strWords(i) = (strWords(i).Substring(1) & strChar1 & "AY")
-
End Select
-
-
'Loop through each word...
-
Next i
-
Catch Sentance As SystemException
-
MessageBox.Show("Please Enter a valid sentence.")
-
Me.txtEnterWords.Focus()
-
End Try
-
-
Hi,
On 11th line write this :
If Trim(txtEnterWords.Text) ="" Then Exit Sub
Regards
Veena
didnt work, it gives me the enter a sentence, but when i click ok. It goes down to the message statements and executes that :/
Hi,
In your Original function write this after 43rd line: -
If Trim(txtEnterWords.Text) ="" Then
-
strCounter = 0
-
Return strCounter
-
Exit Function
-
End If
-
Regards
Veena
That didn't work either, went through the division to get the percentage of vowels and threw a dividebyzero/overflow exception. So i piddled with it and just wrapped the full code as a system exception and it catches everything. Maybe it woulda helped if i would've given you the full code lol. Sorry bout that, but i appreciate you trying. Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: cassandra.flowers |
last post by:
Hi,
I'm using Visual Basic 6 and I'm trying to make a program to change the
colours of traffic lights.
I am using 3 oval shapes, for each light. I want the traffic lights to
change colour...
|
by: chahnaz.ourzikene |
last post by:
Hi all,
This is the first i post in this newsgroup, i hope my english is not too
bad...
Let's get straight to the point ! I have a little probleme using threads in
my little training example :...
|
by: brian.digipimp |
last post by:
Write a program that prompts the user to input a positive integer. It
should then output a message indicating whether the number is a prime
number. (Note: An even number is prime if it is 2. An odd...
|
by: bmlclemson08 |
last post by:
Hey if anyone could I need to find out how to write a program that will
read in any number of integers, including none, and determine which is
the largest integer. The part i can't figure out is...
|
by: news.east.cox.net |
last post by:
Hello,
I'm trying to figure out why the following code won't work for me. The
Firefox javascript console tells me that tableItemClicked is not
defined, but the function is right there in the...
|
by: cJ500 |
last post by:
I can't figure out the problem with this code. I'm using a Borland compiler. The problem is with the / operation overload. When I call isNeg it doesn't output true or false. Now I know this code...
|
by: rookiejavadude |
last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
|
by: Zerofury |
last post by:
Okay this is what i'm attempting to do.
I have to modify this program that i wrote so that it allows the user to list items by alpha as an option on the main menu. Here is my problem. If i sort the...
|
by: yjh0914 |
last post by:
hi guys! so im basically editting my post i made earlier as it wznt as specific..
i have to make a program that basically ranks students by their cumulative gpa. the student's info is on a csv file...
|
by: ccarter45 |
last post by:
Okay, so I need to write this program that first declares an array and inputs the number of each snake present on a plane (there are 5 diff. snakes). Next, it must print out the number of each snake:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |