Welcome to Dream.In.Code
Become a VB Expert!

Join 137,263 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,497 people online right now. Registration is fast and FREE... Join Now!




Difficulties with While loop

 
Reply to this topicStart new topic

Difficulties with While loop

Bobulous
23 Nov, 2006 - 07:52 AM
Post #1

New D.I.C Head
*

Joined: 10 Nov, 2006
Posts: 5


My Contributions
Ok so I'm making a program that converts a word into piglatin, and I'm having huge troubles in making it work. As it is right now, it will convert words that start with vowels properly, but when I input a word that starts with a consonant, I have an error.
text1 is the input box,
text2 is an invisible box,
text3 is the results box
CODE
Private Sub Command1_Click()
Text3.Text = ""
Text2.Text = ""
If Left(Text1.Text, 1) = "A" Or Left(Text1.Text, 1) = "E", etc.
Text3.Text = Text1.Text + "ay"
Exit Sub
End If
While Left(Text1.Text, 1) <> "A" Or Left(Text1.Text, 1) <> "E", etc.
Text2.Text = Text2.Text + Left(Text1.Text, 1)
Text1.Text = Right(Text1.Text, (Len(Text1.Text) - 1))
Text3.Text = Text2.Text + "ay"
Wend
End Sub

User is offlineProfile CardPM
+Quote Post

KeyWiz
RE: Difficulties With While Loop
23 Nov, 2006 - 08:32 AM
Post #2

D.I.C Regular
Group Icon

Joined: 26 Oct, 2006
Posts: 428


Dream Kudos: 125
My Contributions
QUOTE(Bobulous @ 23 Nov, 2006 - 08:52 AM) *

Ok so I'm making a program that converts a word into piglatin, and I'm having huge troubles in making it work. As it is right now, it will convert words that start with vowels properly, but when I input a word that starts with a consonant, I have an error.
text1 is the input box,
text2 is an invisible box,
text3 is the results box
CODE
Private Sub Command1_Click()
Text3.Text = ""
Text2.Text = ""
If Left(Text1.Text, 1) = "A" Or Left(Text1.Text, 1) = "E", etc.
Text3.Text = Text1.Text + "ay"
Exit Sub
End If
While Left(Text1.Text, 1) <> "A" Or Left(Text1.Text, 1) <> "E", etc.
Text2.Text = Text2.Text + Left(Text1.Text, 1)
Text1.Text = Right(Text1.Text, (Len(Text1.Text) - 1))
Text3.Text = Text2.Text + "ay"
Wend
End Sub




What you are doing in your While - Wend is simply stripping the characters off one at a time untill there is nothing left. Use AND instead of OR.

also when you are repeating the same function again and again, use a variable.

try this


CODE

dim myVar as string
myVar = LCASE(LEFT(text1text,1))
' this will check for leading vowels, if the letter is not a vowel then the procedure will continue.
WHILE myVar <> "a" AND myVar <> "e" AND myVar <> "i" AND myVar <> "o" AND myVar <> "u" AND myVar <> "y"
' by using OR every letter is NOT an A or NOT an E, etc.

         'your code here

WEND


This post has been edited by KeyWiz: 23 Nov, 2006 - 08:35 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:16PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month