Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, to clean up your code a bit. </p> <ul> <li>Instead of using all those Else If statement, a better approach is to use Select Case.</li> <li>You don't have to Int() on your 3rd or 4th line. It's already an Integer.</li> <li>You also don't have to repeat the string of "You zodiac sign is ". Just use it once.</li> <li>And as Deanna said, you need to remove the ASCII 13 from your textbox input.</li> </ul> <p>So, the new code:</p> <pre><code>Private Sub txtInput_KeyPress(KeyAscii As Integer) Dim ZodiacAnimal As String If KeyAscii = 13 Then curyear = 2013 a = (curyear - txtInput.Text) Mod 12 Select Case a Case 9, -3 ZodiacAnimal = "Snake" Case 8, -4 ZodiacAnimal = "Dragon" Case 7, -5 ZodiacAnimal = "Rabbit" Case 6, -6 ZodiacAnimal = "Tiger" Case 5, -7 ZodiacAnimal = "Ox" Case 4, -8 ZodiacAnimal = "Rat" Case 3, -9 ZodiacAnimal = "Pig" Case 2, -10 ZodiacAnimal = "Dog" Case 1, -11 ZodiacAnimal = "Rooster" Case 0, -2 ZodiacAnimal = "Monkey" Case 11, -1 ZodiacAnimal = "Sheep" Case 12, 0 ZodiacAnimal = "Horse" End Select txtInput.Text = "Your zodiac sign is " &amp; ZodiacAnimal KeyAscii to 0 End If End Sub </code></pre> <p>Now, a couple other problems I see.</p> <ul> <li>You have the year hard coded. The zodiac is about the year you were born, and doesn't have anything to do with the current year.</li> <li>You have 0 listed twice.</li> </ul> <p>Now, this may be too advanced for you, but here's how I would have coded it:</p> <pre><code>Private Sub txtInput_KeyPress(KeyAscii As Integer) Dim ZodiacAnimal() As String If KeyAscii = 13 Then ZodiacAnimal = Split("Monkey,Rooster,Dog,Pig,Rat,Ox,Tiger,Rabbit,Dragon,Snake,Horse,Goat", ",") txtInput.Text = "Your zodiac sign is " &amp; ZodiacAnimal(Y Mod 12) KeyAscii to 0 End If End Sub </code></pre> <p>This makes ZodiacAnimal an array of the animals. Then using the Mod function, I get the right index of the array. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload